# 算术运算符 # 除法:结果是浮点数 a = 10 / 3#3.3333333333333335 print(a) # 除法:结果是整数 a = 11 // 2 print(a)#5 # 求余 b = 10 % 3 print(b)#1 # 同时得到商和余数 c, d = divmod(10, 3) print(c, d,sep=‘---------------‘)#3---------------1 # 求幂 # e = 2 ** 4 e = pow(2, 4) print(e)#16 # 复合运算符 a = 10 b = 20 # a = a + b # 与上式等价 a += b print(a)#30 # 关系运算 print(3 < 2)#False # 逻辑运算 a = 200 # 其他语法也通用的写法 print(a > 10 and a < 100)#False # python中特有的形式 print(10 < a < 100)#False print(a%3 == 0 and a%5 == 0)#False print(a%3 == 0 or a%5 == 0)#True y = int(input(‘请输入一个年份:‘)) print((y%4==0 and y%100!=0) or (y%400==0)) lt = [1, 2, 3] print(8 not in lt)#True dt = {‘name‘:‘dahua‘, ‘age‘: 18} # 对于字典,判断的是键 print(‘name‘ in dt)#True
原文:https://www.cnblogs.com/liangliangzz/p/10137959.html