python中的比较运算符有8个。
运算 | 含义
=============
< | 小于
<= | 小于等于
> | 大于
>= |大于等于
== | 等于
!= |不等于
is | 是
is not | 不是
例子:
>>> 1 is not 2
True
>>> 1 is 1
True
>>> 1 is 2
False
>>> 1 == 1
True
>>> 1 != 1
False
拓展:
in
not in
这2个运算符,用在序列对象中(列表、元组)
>>> 1 in [1,2]
True