本文共 816 字,大约阅读时间需要 2 分钟。
说明:
>>> help(bool)Help on class bool in module __builtin__: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.实例:
#!/usr/bin/env python #coding:utf-8 #整数0,浮点数0.0,空列表,空元组,空字典,空字符串,均为False print bool(0.0),bool(0),bool([]),bool(()),bool({}),bool('')#正数,负数均为Trueprint bool(8),bool(-3),bool(-3.9),bool(9.8)#非空列表,非空元组,非空字典,非空字符串均为Trueprint bool([2,3]),bool((3,4)),bool({'name':'song'}),bool('python')结果:
False False False False False False
True True True True True True True True另外,注意:bool是int的子类:
>>> issubclass(bool,int)True>>>
bool类只有True和False两个实例:
>>> isinstance(True,bool)True>>> isinstance(False,bool)True(完)
转载地址:http://knyai.baihongyu.com/