Skip to content

Instantly share code, notes, and snippets.

@shuson
Created June 25, 2013 09:56
Show Gist options
  • Select an option

  • Save shuson/5857332 to your computer and use it in GitHub Desktop.

Select an option

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.
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