demo1

>>> print(True == 1)
>>> print(True == 2)
>>> print(False == 0)
>>> print(False == 2)
True
False
True
False

这说明1与True,0与False在python来说是完全相等的东西。

demo2

>>> x = 5
>>> if x%2:
>>> x += 1
>>> else:
>>> x -= 1
>>> print(x)

在demo2中可以看出二者之间关系的妙用。
x%2=0 <——> x%2 = True

---------------------
版权声明:本文为CSDN博主「Bruce chen」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cpc784221489/article/details/90721228

05-14 01:39
查看更多