forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Python Boolean Operations
Quincy Larson edited this page Aug 20, 2016
·
1 revision
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.
- not has a lower priority than non-Boolean operators, so not a == b is interpreted as not (a == b), and a == not b is a syntax error.
>>> not True
False
>>> not False
True
>>> True and False # Short-circuited at first argument.
False
>>> False and True # Second argument is evaluated.
False
>>> True and True # Second argument is evaluated.
True
>>> 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
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links