有人能解释一下这些赋值语句背后的逻辑吗。你知道吗
>>> True
True
>>> True = False
>>> True
False
>>> True = True
>>> True
False
>>> a = True
>>> if a:
... print "a is True"
... else:
... print "a is False"
...
a is False
根据手册,bool类仅有的两个实例是True
和False
。你知道吗
Help on bool object:
True = class bool(int)
| bool(x) -> bool
|
| Returns True when the argument x is true, False otherwise.
| The builtins True and False are the only two instances of the class bool.
| The class bool is a subclass of the class int, and cannot be subclassed.
|
| Method resolution order:
| bool
| int
| object
那么我要重写默认实例吗?如果是这样,为什么python在下面的赋值中不将True
赋值给is default实例?如何在下面的语句中指定默认的pythonTrue
?你知道吗
>>> True = False
>>> True
False
>>> True = True
>>> True
False #why?
提前感谢您的帮助!!!你知道吗
当您这样做时:
True
变成False
。。当你这么做的时候:就像在写:
如果您想让它再次成为“原始”
True
,您应该:相关问题 更多 >
编程相关推荐