In Python, any object can be judged by its true or false value: True,false
In the If or while condition judgment, the following case value is false:
1.None
2.Flase
3. The case of a value of 0, such as: 0,0.0,0j
4. All empty sequences, such as: ", (), []
5. All empty mapping, such as: {}
6.instances of user-defined classes, if the class defines a __bool__ () or __len__ () method,
When that method returns the integer zero or bool value False.
All other values is considered true-so objects of many types is always true.
Returns a Boolean result of 0 or flase for false in operation and built-in functions
1 or True indicates true
The Boolean operations in Python are as follows:
Print (' x or Y, if x is False,then y, else X ') x, y = 2, 0print (' {} or {} = {} '. format (x, y, x or y)) x1, y1 = 0, 10pri NT (' {} or {} = {} '. Format (x1, y1, x1 or y1)) x2, y2 = 0, 0print (' {} or {} = {} '. Format (x2, y2, x2 or y2)) print (' # ' * 5 0) print (' X and Y, if X is False,then x, else y ') print (' {} and {} = {} '. format (x, y, x and y)) x1, y1 = 0, 10print (' {} and {} = {} '. Format (x1, y1, x1 and y1)) x2, y2 = 0, 0print (' {} and {} = {} '. Format (x2, y2, X2 and y2)) print (' # ' * 50) Print (' Not X--if x is False,then true,else false ') x = 2print (' not {} = {} '. Format (x, not x)) x = 0print (' not {} = {} ') . format (x, not X))
Operation Result:
>>>
X or Y, if x is False,then y, else x
or 0 = 2
or 10 = 10
or 0 = 0
##################################################
X and y if x is False,then x, else y
and 0 = 0
and 10 = 0
and 0 = 0
##################################################
Not X-if x is False,then true,else false
Not 2 = False
Not 0 = True
>>>