1.7 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			1.7 KiB
		
	
	
	
	
	
	
	
title
| title | 
|---|
| Python Boolean Operations | 
Python Docs - Boolean Operations
These are the Boolean operations, ordered by ascending priority:
| Operation | Result | Notes | 
|---|---|---|
| x or y | if x is false, then y, else x | (1) | 
| x and y | if x is false, then x, else y | (2) | 
| not x | if x is false, then True, else False | (3) | 
Notes:
- This is a short-circuit operator, so it only evaluates the second argument if the first one is False.
- This is a short-circuit operator, so it only evaluates the second argument if the first one is True.
- nothas a lower priority than non-Boolean operators, so- not a == bis interpreted as- not (a == b), and- a == not bis a syntax error.
Examples:
or:
>>> True or False    # Short-circuited at first argument.
True
>>> False or True    # Second argument is evaluated.
True
>>> False or False   # Second argument is evaluated.
False
and:
>>> True and False    # Second argument is evaluated.
False
>>> False and True    # Short-circuted at first argument.
False
>>> True and True     # Second argument is evaluated.
True
not:
>>> not True
False
>>> not False
True
>>> False or False   # Second argument is evaluated.
False