熟悉运算符号
+ | plus | 加号 |
|
- | minus | 减号 |
|
/ | slash | 斜杠 | 除法 |
* | asterisk | 星号 | 乘法 |
% | percent | 百分号 | 除法的余数 |
< | less-than | 小于号 |
|
> | Greater-than | 大于号 |
|
<= | Less-than-equal | 小于等于号 |
|
>= | Greater-than-equal | 大于等于号 |
|
例:
Python2 1/2=0 1//2=0 1/2.0=0.5
Python3 1/2=0.5 1//2=0 1/2.0=0.5
print("I will now count my chickens:")
#母鸡数量
print("Hens", 25 + 30 / 6)
#公鸡数量
print("Roosters", 100 - 25 * 3 % 4)
#鸡蛋数量
print("Now I will count the eggs:")
#此处为python3,1/4=0.25,如为python2 1/4=0 结果为7
print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
#比较返回True和False
print ("Is it true that 3 + 2 < 5 - 7?")
print(3 + 2 < 5 - 7)
print ("What is 3 + 2?", 3 + 2)
print ("What is 5 - 7?", 5 -7)
print (" Oh, that's why it's False.")
print ("How about some more.")
print ("Is it greater?", 5 > -2)
print ("Is it greater or equal?", 5 >= -2)
print ("Is it less or equal?", 5 <= -2)
打印结果