python-small-examples

@author jackzhenguo
@desc
@tag
@version 
@date 2020/04/05

1 常见算术运算

x, y = 3, 2
print(x + y) # = 5 
print(x - y) # = 1 
print(x * y) # = 6 
print(x / y) # = 1.5 
print(x // y) # = 1 
print(x % y) # = 1 
print(-x) # = -3 
print(abs(-x)) # = 3 
print(int(3.9)) # = 3 
print(float(x)) # = 3.0 
print(x ** y) # = 9

大多数操作符都是不言自明的。注意,//运算符执行整数除法。结果是一个向下舍入的整数值(例如,3//2==1)

[上一个例子](/python-small-examples/md/197.html) [下一个例子](/python-small-examples/md/199.html)