table of Contents
A Boolean value (bool)
1.1 What is a Boolean type
Boolean data type is the same, he appeared in the conditions used to determine the results, such as True (true) or False (false)
1.2 Definitions Method
True, False usually not directly quoted, required logic operation result obtained.
1.3 Use
print(type(True))
print(True)
Output:
<class 'bool'>
True
print(bool(0))
print(bool('xucheng'))
print(bool(1 > 2))
print(bool(1 == 1))
Output:
False
True
False
True
Note: Python values of all data types comes Boolean value. So much data types only need to remember only 0, None, an empty, False Boolean value is False, the rest to True.
print(bool(0))
print(bool(None))
print(bool(''))
print(bool([]))
print(bool({}))
print(bool(False))
Output:
False
False
False
False
False
False