Detailed explanation of the usage of python function bool([x])

巴扎黑
Release: 2017-08-21 13:45:23
Original
4183 people have browsed it

bool([x])

English description: 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.

Chinese description: Convert x to Boolean type, if x By default, False is returned, and bool is also a subclass of int;

Parameter x: any object or default; everyone noticed: [x] is used here, indicating that the x parameter is optional. If no parameters are given, False will be returned.

Version: The new function introduced in python 2.2.1 will return False if no parameters are passed after python2.3.

Note: This function can also be used normally in python3

Example:

>>> bool(0)
False
>>> bool("abc")
True
>>> bool("")
False
>>> bool([])
False
>>> bool()
False
>>> issubclass(bool, int) #bool是一个subclass int
True
Copy after login

The above is the detailed content of Detailed explanation of the usage of python function bool([x]). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template