Python bool() Function

Python 内置函数Python Built-in Functions


Description

bool()The function is used to convert the given parameter to a boolean type, and returns False if there is no parameter.

bool is a subclass of int.

Syntax

The following is the syntax of the bool() method:

class bool([x])

Parameters

  • x -- The parameter to be converted.

Return Value

Returns True or False.


Examples

The following shows examples of using the bool function:

>>>bool() False >>> bool(0) False >>> bool(1) True >>> bool(2) True >>> issubclass(bool, int) # bool is a subclass of int True

Python 内置函数Python Built-in Functions

Other Extensions