python中True 为1 ,False为0
demo1
>>> print(True == 1)
>>> print(True == 2)
>>> print(False == 0)
>>> print(False == 2)
True
False
True
False
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
这说明1与True,0与False在python来说是完全相等的东西。
demo2
>>> x = 5
>>> if x%2:
>>> x += 1
>>> else:
>>> x -= 1
>>> print(x)
6
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
在demo2中可以看出二者之间关系的妙用。
x%2=0 <——> x%2 = True
https://blog.youkuaiyun.com/cpc784221489/article/details/90721228