pub-3785248829033902 | Python: ELIF | - Big data with Python

| Python: ELIF |

The elif (short for else if) statement is a shortcut to use when chaining if and else statements.

A series of if elif statements can have a final else block, which is called if none of the if or elif expressions is True. 


The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the elif statement in Python:

Æ’ python command

my_birthday = 4
if my_birthday == 3:
   print("my_birthday is on 3")
elif my_birthday == 2:
   print("my_birthday is on 2")
elif my_birthday == 1:
   print("my_birthday is on 1")
elif my_birthday == 4:
   print("my_birthday is on 4")
else:
   print("my_birthday isn't on 3, 2 or 1")

output

my_birthday is on 4


Previous
Next Post »