python里面的数学

一.基本运算符

1.算数运算

 

2.比较运算

特殊情况:!= 不等于 新版本不支持 <> 不等号

3.赋值运算

4.逻辑运算

not : 非   非真即假,非假即真.   -

and : 并且    左右两端同时为真,结果才为真.   *

or : 或者      左右两端有一个为真,结果就是真.   +

True : 真    1    判断的结果

False : 假   0     判断的结果

print(3 > 4 or 4 < 3 and 1 == 1)  # False
print(1 < 2 and 3 < 4 or 1 > 2)  # True
print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # True
print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # False
print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False
print((not 2 > 1 and 3 < 4) or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False

当出现  x or y 时 , 判断x是否为0 ; 如果x==0 ,则返回y ,否则返回x.(x and y 恰恰相反)

5.成员运算

in : 包含     字符串  in  字符串   

     字符串 in 列表  等等

content = input("请输入你的评论:")
if "马冬梅" in content :   #判断content里面有没有马冬梅
    print("你的评论不合法!")
else:
    print("你的评论的是合法的!")

ad = input("请输入你的广告词:")
if "最" in ad or "第一" in ad or "全球" in ad :  # or 满足任何一个都不合法
    print("你的广告词不合法!")
else:
    print("你的广告词合法!")
posted @ 2018-11-27 19:30  雾霾1024  阅读(287)  评论(0编辑  收藏  举报