python算术运算符
#!/usr/bin/env python
#-*- coding: utf-8 -*-
a = 21
b = 10
c = 0
c = a + b
print (“1.c的值为:”,c)
c = a – b
print (“2.c的值为:”,c)
c = a * b
print (“3.c的值为:”,c)
c = a / b
print (“4.c的值为:”,c)
c = a % b
print (“5.c的值为:”,c)
# 修改变量 a 、b 、c
a = 2
b = 3
c = a**b
print (“6.c的值为:”,c)
a = 10
b = 5
c = a//b
print (“7.c的值为:”,c)
以上实例输出结果:
1.c的值为: 31
2.c的值为: 11
3.c的值为: 210
4.c的值为: 2.1
5.c的值为: 1
6.c的值为: 8
7.c的值为: 2
python比较运算符
以下实例演示了python所有比较运算符的操作:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
a = 21
b = 10
c = 0
if (a == b):
print (“1. a 等于 b”)
else:
print (“1. a 不等于 b”)
if ( a != b):
print (“2. a 不等于 b”)
else:
print (“2. a 等于 b”)
if ( a < b ):
print ("4. a 小于 b")
else:
print ("4. a 大于 b")
if ( a > b ):
print (“5. a 大于 b”)
else:
print (“6. a 小于 b”)
if ( a >= b ):
print (“7. a 大于等于 b”)
else:
print (“7. a 小于 b “)
if ( a