概述
'''and 并且,与
or 或
not 非
逻辑运算的运算顺序:()> not > and > or'''
print(3 > 4 or 4 < 3 and 1 == 1) #f or f and t => f or f => f
print(1 < 2 and 3 < 4 or 1 > 2) #t and t or f => t or f => t
print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) #t and t or f and f => t or f =》 t
print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) #f and t or f and t or f => f or f or f => f
print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) #f and f or f and t and t or f => f or f and t or f => f
print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) #f and t or f and t and t or f => f or f or f => f
'''打印结果:
False
True
True
False
False
False
总结:使用负责的逻辑运算的时候切记加括号。'''
print(bool(0)) #False
print(bool(1)) #True
print(bool(-1)) #True
print(bool("")) #False
print(bool(" ")) #True
print(bool("哈哈")) #True
print(bool([])) #False
print(bool([1, 2, 3])) #True
print(bool({})) #False
'''结论:所有表示空的东西都是False。'''
最后
以上就是自由哈密瓜为你收集整理的python中3 and not 5_python3 not and or逻辑运算顺序的全部内容,希望文章能够帮你解决python中3 and not 5_python3 not and or逻辑运算顺序所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复