Python函数-bool()

bool([x])

作用:

       将x转换为Boolean类型,如果x缺省,返回False,bool也为int的子类;

参数x:

       任意对象或缺省;大家注意到:这里使用了[x],说明x参数是可有可无的,如果不给任何参数则会返回False。

 1 >>> bool(0)
 2 False
 3 >>> bool("abc")
 4 True
 5 >>> bool("")
 6 False
 7 >>> bool([])
 8 False
 9 >>> bool()
10 False
11 >>> issubclass(bool, int) #bool是一个subclass int
12 True
原文地址:https://www.cnblogs.com/guyuyuan/p/6910862.html