发布时间:2019-08-24 09:24:04编辑:auto阅读(2171)
优先级
1. and 与 2. or 或 3. not 非
运算
要记住:数字中非零为真零为假;True 为真 False 为假。
or :与and相反,任意一个真即为真,同假才为假(因为要挨个查验是否有真,所以假的情况下值为最后一个假值,例如:0 or False 为 False;False or 0 则为0。真的情况下值为第一个真值,例如:0 or 1 or 2 为 1;0 or False or 2 为 2)
and :与or相反,任意一个假即为假,同真为真(因为要挨个检查是否有假,所以真的情况下值为最后一个真值,例如:True and 1 为 1;1 and True 则为True。假的情况下值为第一个假值,例如:0 and 1 and 2 为 0;True and False 为 False;True and 0 and False 为 0)
not :对高优先级的运算结果取反,值为布尔(2为真,取反为假:False)
not 2:False
not 1 and 2:False
not 1 or 2:False
not not 1:True
not 0 :True
其实不只是Python中,所有的语言都是遵循这个逻辑的
上一篇: python实现的简版iconv
下一篇: Python 5.5 使用元类
48900
47984
38758
35891
30318
27087
26098
20933
20750
19112
593°
670°
661°
667°
639°
610°
690°
755°
882°
1042°