if, elif and else in Python
In this post, you will learn how to work with decisions (if, elif and else) so that you can use that same knowledge and thus evolve.
'''
(if) condition is true:
the code inside the if is executed
(elif) condition is true (elif only occurs when the if condition is false):
the code inside the elif is executed
(else) without condition (only occurs when the if/elif conditions are false):
the code inside the else is executed
'''
x = 30
if x == 10:
print('The value of x is equal to 10.')
elif x == 20:
print('The value of x is equal to 20.')
else:
print('The value of x is different from 10 and 20.')
# The value of x is different from 10 and 20.
Don’t forget to watch the video and you can always read this post in Portuguese.