Skip to content

Instantly share code, notes, and snippets.

@cshoe
Created January 14, 2013 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cshoe/4531451 to your computer and use it in GitHub Desktop.
Save cshoe/4531451 to your computer and use it in GitHub Desktop.
Proving that Python only evaluates to the first `True` value in an or statement.
def first_function(return_value):
"""Returns `return_value`.
"""
print 'Running FIRST function'
return return_value
def second_function(return_value):
"""Returns `return_value`.
"""
print 'Running SECOND function'
return return_value
def third_function(return_value):
"""Returns `return_value`.
"""
print 'Running THIRD function'
return return_value
def main():
if first_function(True) or second_function(False):
print 'first clause is True'
if first_function(False) or second_function(True) or third_function(True):
print 'second clause is True'
if first_function(False) or second_function(False) or third_function(True):
print 'third clause is True'
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment