How to use bool function?

藏色散人
Release: 2019-03-07 14:41:38
Original
22032 people have browsed it

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])
Copy after login

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
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!