Home  >  Article  >  Backend Development  >  Detailed explanation of the usage of python function bool([x])

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

巴扎黑
巴扎黑Original
2017-08-21 13:45:234174browse

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

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!

Statement:
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