python 中的True和1及False和0是可以等价比较的
测试如下:
[[email protected] root]# cat test_true_false.py
ok=0
if ok:
print ok
ok=1
if ok:
print ok
ok=True
if ok:
print ok
ok=False
if ok:
print ok
print ‘*‘*20
ok=0
if ok == False:
print ok
ok=1
if ok == True:
print ok
ok=False
if ok ==0:
print ok
ok=True
if ok == 1:
print ok
[[email protected] root]#
[[email protected] root]# python test_true_false.py
1
True
********************
1
False
True
[[email protected] root]#