本文摘自php中文网,作者巴扎黑,侵删。
bool([x])
英文说明:Convert a value to a Boolean, using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.
New in version 2.2.1.
Changed in version 2.3: If no argument is given, this function returns False.
中文说明:将x转换为Boolean类型,如果x缺省,返回False,bool也为int的子类;
参数x:任意对象或缺省;大家注意到:这里使用了[x],说明x参数是可有可无的,如果不给任何参数则会返回False。
版本:在python 2.2.1中引入的新函数,在python2.3以后如果不传参数则返回False。
注意:该函数在python3中也可正常使用
实例:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
以上就是python函数之bool([x])用法详解的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
使用 if x is not none 还是if not x is none
Python创建列表和向列表添加元素的实现方法_Python
更多相关阅读请进入《Python》频道 >>

Python编程 从入门到实践 第2版
python入门书籍,非常畅销,超高好评,python官方公认好书。