首页 > 后端开发 > Python教程 > python函数 - bool([x])

python函数 - bool([x])

高洛峰
发布: 2016-10-17 15:35:25
原创
1402 人浏览过

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中也可正常使用

实例:

>>> bool(0)
False
>>> bool("abc")
True
>>> bool("")
False
>>> bool([])
False
>>> bool()
False
>>> issubclass(bool, int) #bool是一个subclass int
True
登录后复制


   


相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
python把第x列数据写入第x个文件
来自于 1970-01-01 08:00:00
0
0
0
python小白 问关于匿名函数的问题
来自于 1970-01-01 08:00:00
0
0
0
“INET6_ATON” SQL 函数的 Python 等效项
来自于 1970-01-01 08:00:00
0
0
0
c++ - 如何在python的阻塞的函数中获取变量值
来自于 1970-01-01 08:00:00
0
0
0
python2.7 - python 函数或者类 代码的执行顺序
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板