Utilizor
Contact Us

Python If...Else

Conditional statements.

Examples

If Statement

Basic if statement.

a = 33
b = 200
if b > a:
  print("b is greater than a")

Elif

elif says 'if the previous conditions were not true, then try this condition'.

a = 33
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")

Else

else catches anything which isn't caught by the preceding conditions.

a = 200
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")
else:
  print("a is greater than b")

Test Your Knowledge

Python Quiz

No quiz available for this topic yet.