Home >Backend Development >Python Tutorial >How to use bool function?

How to use bool function?

藏色散人
藏色散人Original
2019-03-07 14:41:3822087browse

Python bool() is used to determine whether the object is True, and the return value is True or False.

How to use bool function?

#bool() function is used to convert the given parameter to a Boolean type. If there are no parameters, it returns False.

bool is a subclass of int.

bool() syntax:

class bool([x])

Parameters: x represents the parameter to be converted.

Return value: Return True or False.

Example of using the bool() function:

The code is as follows:

>>>bool()
False
>>> bool(0)
False
>>> bool(1)
True
>>> bool(2)
True
>>> issubclass(bool, int)  # bool 是 int 子类
True

Recommended related video tutorials: "Python Tutorial"

This article is an introduction to the usage of the bool function in Python. I hope it will be helpful to friends in need!

The above is the detailed content of How to use bool function?. 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