#
IF ... ELIF ... ELSE in Python
This tutorial give you some example of using IF ... ELSE command in Python.
Using IF ... ELIF ... ELSE statement in Python is very easy. Here are some examples:
Example #1
year=2000
if year == 2000:
print ('The year is '+str(2000))
if year > 1900:
print('The year is > ' + str(1900))
print('End Program')
And here you can see the execution of the Python code in PyCharm:
Example #2
year=2000
if year != 2000:
print ('The year is NOT'+str(2000))
else:
print ("Here is ELSE ...")
print('End Program')
And here you can see the execution of the Python code in PyCharm:
Example #3
year=2000
if year != 2000:
print ('The year is NOT '+str(2000))
elif year == 2001:
print('The year is ' + str(2001))
# TRUE
elif year == 2000:
print('The year is ' + str(2000))
# TRUE
elif year >= 1001:
print('The year is >= ' + str(1001))
else:
print ("Here is ELSE ...")
print('End Program')
And here you can see the execution of the Python code in PyCharm: