English documents:
-
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
. bool
The class is a subclass of int
(see Numeric Types-int, float, complex). It cannot be subclassed further. Its is only instances is and False
True
(see Boolean Values).
-
Description
1. A Boolean value that returns a value of TRUE or False
-
2. Returns False if the parameter is default
-
# parameter not passed in False
3. Parameter conversions use standard logic test expressions
3.1 When you pass in a Boolean type, return by the original value
>>> bool (true) True>>> bool (false) False
3.2 An empty string returns False if the string is passed in, otherwise true
>>> bool (') False>>> bool ('0') True
3.3 When the value is passed in, 0 returns false, otherwise true
>>> bool (0) False>>> bool (1) True>>> bool ( -1.0) True
3.4 When passing in tuples, lists, dictionaries, and other objects, the number of elements is null returns FALSE, otherwise true
>>> bool (())#Empty tupleFalse>>> bool ((0,))#non-null tupleTrue>>> bool ([])#Empty listFalse>>> bool ([0])#non-empty listTrue>>> bool ({})#Empty DictionaryFalse>>> BOOL ({'k':'v'})#non-empty dictionariesTrue
Python built-in functions (6)--bool