Python Conditional Statements

  • indentation replace curly braces used in C/C++, Java
  • elif is short for else if
  • you can use < (less than), > (greater than), == (equal to), <= (less than or equal to), >= (greater than or equal to) and != (not equal to) in your conditions

Python Conditional Statements Example 1

x = 1
if x > 0:
	print 'positive'

Python Conditional Statements Example 2

x = 1
if x < 0:
	print 'negative'
else:
	print 'positive'

Python Conditional Statements Example 3

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