老齐python-基础5(运算符、语句)
1、运算符 1.1算术运算符 1.2比较运算符 >>> a = 10 >>> b = 20 >>> a > b False >>> a < b True >>> a == b False >>> a != b True >>> a <= b True >>> a >= b False >>> a = 'tajzhang' >>> b = 'python' >>> a > b True >>> a = 5 >>> b = '5' >>> a > b Traceback (most recent call last): File "<pyshell#13>", line 1, in <module> a > b TypeError: '>' not supported between instances of 'int' and 'str' 1.3逻辑运算符 1)布尔类型 True False >>> a = " " >>> bool(a) True >>> b = "" >>> bool(b) False >>> bool("canglaoshi") True >>> bool([]) False >>> bool({}) False 2)布尔运算 and or not and: 与 A and B:如果A的值是True,就计算B,并将B的结果返回作为最终结果