2018-12-18
阅读量:
811
python常用的运算函数(1)
Python为模块“operator”下的许多数学,逻辑,关系,按位等操作预定义了函数。下面介绍一些常用的运算函数。
1.加(A,B) :-该函数返回另外的给定的参数。
操作 - a + b。
2. sub(a,b): - 此函数返回给定参数的差异。
操作 - a - b。
3. mul(a,b): - 此函数返回给定参数的乘积。
操作 -a * b。
# Python code to demonstrate working of
# add(), sub(), mul()
# importing operator module
import operator
# Initializing variables
a = 4
b = 3
# using add() to add two numbers
print ("The addition of numbers is :",end="");
print (operator.add(a, b))
# using sub() to subtract two numbers
print ("The difference of numbers is :",end="");
print (operator.sub(a, b))
# using mul() to multiply two numbers
print ("The product of numbers is :",end="");
print (operator.mul(a, b))
输出:






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论