Home > Article > Backend Development > Detailed introduction to Python’s built-in bool function
English document:
class bool
([x])
Return a Boolean value, i.e. one of True
or False
. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False
; otherwise it returns True
. The bool
class is a subclass of int
(see Numeric Types — int, float, complex). It cannot be subclassed further. Its only instances are False
and True
(see Boolean Values).
Instructions:
1. The return value is a Boolean value of True or False
2. If the parameter is default, False will be returned
>>> bool() #未传入参数 False
3. Parameter conversion uses standard logical test expressions
3.1 When the Boolean type is passed in, the original value will be used Return
>>> bool(True) True >>> bool(False) False
3.2 When a string is passed in, the empty string returns False, otherwise True
>>> bool('') False >>> bool('0') True
3.3 Pass in a value When the value is 0, False is returned, otherwise True is returned Otherwise return True
>>> bool(0) False >>> bool(1) True >>> bool(-1.0) True
The above is the detailed content of Detailed introduction to Python’s built-in bool function. For more information, please follow other related articles on the PHP Chinese website!