Created
June 25, 2013 09:56
-
-
Save shuson/5857332 to your computer and use it in GitHub Desktop.
For those who are familiar with "? :" in C, but "and or" usage in python is a little different.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = 'a' | |
| b = 'b' | |
| print True and a or b | |
| # output is 'a' | |
| c = '' #bool(c) is False | |
| d = 'd' | |
| print True and c or d | |
| #output is 'd' | |
| # | |
| # from the outputs above, we find the variables as flank with 'or' have to be True | |
| # Non-Empty str, list, tuple and non-0 int | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment