fabsta
8/28/2016 - 8:26 PM

9. conditiional statements (python).md

CONDITIONAL STATEMENTS

if statement

if x > 0:
    print 'positive'

if/else statement

if x > 0:
    print 'positive'
else:
    print 'zero or negative'

if/elif/else statement

if x > 0:
    print 'positive'
elif x == 0:
    print 'zero'
else:
    print 'negative'

single-line if statement (sometimes discouraged)

if x > 0: print 'positive'

single-line if/else statement (sometimes discouraged)

known as a 'ternary operator'

'positive' if x > 0 else 'zero or negative'