filmov
tv
ELIF Statements in Python (IF, ELIF, ELSE) - Conditional Statements - Python Tutorial for Beginners
Показать описание
🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!
🖥️ ELIF Statements in Python (IF, ELIF, ELSE) - Conditional Statements in Python
Sometimes, there are more than two possibilities, so you need more than two branches. Fortunately, there is one more conditional statement in Python, which is used to test out more expressions, in order to optimise and increase the efficiency of your code.
One way to express such a computation, is called: a chained conditionals - or ELSE-IF in Python (ELIF).
Let's take a look at its syntax, to understand how you can declare an else-if statement block, in Python.
if expression_1:
statement(s)
elif expression_2:
statement(s)
elif expression_3:
statement(s)
...
else:
statement(s)
Each condition is checked in order. If the first is False: the next is checked. If the second is False: the next is checked, and so on. If one of them is True, then the corresponding branch executes, and the statement ends. Even if more than one condition is True in the following statements, ONLY the first True branch will be executed.
There is no limit of the number of ELSE-IF statements, but only a single - and optional - final else statement is allowed, and it must be the last branch in the statement. If an else clause is not included and ALL the conditions are False, then NONE of the blocks will be executed.
Let's play this video, stick around and watch until the end of this video! 👍🏻
- Digital Academy™ 🎓
***
☞ WATCH NEXT:
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
♡ SUPPORT US ♡
***
🖥️ ELIF Statements in Python (IF, ELIF, ELSE) - Conditional Statements in Python
Sometimes, there are more than two possibilities, so you need more than two branches. Fortunately, there is one more conditional statement in Python, which is used to test out more expressions, in order to optimise and increase the efficiency of your code.
One way to express such a computation, is called: a chained conditionals - or ELSE-IF in Python (ELIF).
Let's take a look at its syntax, to understand how you can declare an else-if statement block, in Python.
if expression_1:
statement(s)
elif expression_2:
statement(s)
elif expression_3:
statement(s)
...
else:
statement(s)
Each condition is checked in order. If the first is False: the next is checked. If the second is False: the next is checked, and so on. If one of them is True, then the corresponding branch executes, and the statement ends. Even if more than one condition is True in the following statements, ONLY the first True branch will be executed.
There is no limit of the number of ELSE-IF statements, but only a single - and optional - final else statement is allowed, and it must be the last branch in the statement. If an else clause is not included and ALL the conditions are False, then NONE of the blocks will be executed.
Let's play this video, stick around and watch until the end of this video! 👍🏻
- Digital Academy™ 🎓
***
☞ WATCH NEXT:
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
♡ SUPPORT US ♡
***
Комментарии