操作符 含义 == 等于 != 不等于 < 小于 > 大于 <= 小于等于 >= 大于等于
比较两个值,求值为True 或者 False
>>> 'come' == 'come' True >>> 'go' == 'come' False >>> true == true Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'true' is not defined >>> True == True True >>> 20 == 20.0 True >>> 20 == '20' False >>>
如上图:
1.如果两边的值一样,==(等于)的求值为True;
2.如果两边的值不同,!=(不等于)求值为True;
3.==和!=操作实际实际上可以用于所有数据类型的值;
注意:整型或浮点型永远不会与字符串相等,如上图的 20 与 ‘20’
操作符号“==”和“=”的区别:
1.“==”是表示两个值是否相同;
2.“=”是表示将右边的值放到左边的变量中;例如 age = 20;