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免费学习笔记(深入)”;
这本书给出了一份关于python这门优美语言的精要的参考。作者通过一个完整而清晰的入门指引将你带入python的乐园,随后在语法、类型和对象、运算符与表达式、控制流函数与函数编程、类及面向对象编程、模块和包、输入输出、执行环境等多方面给出了详尽的讲解。如果你想加入 python的世界,David M beazley的这本书可不要错过哦。 (封面是最新英文版的,中文版貌似只译到第二版)
1
版本:在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
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号