Home >Backend Development >Python Tutorial >python function - bool([x])

python function - bool([x])

高洛峰
高洛峰Original
2016-10-17 15:35:251374browse

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 is default, return False, 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: A new function introduced in python 2.2.1. After python2.3, it returns False if no parameters are passed.

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



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