ELIF Statements in Python (IF, ELIF, ELSE) – Conditional Statements in Python

🎓 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:
○ Data Types in Python – https://youtu.be/cweUByxBWiU
○ Operators in Python – https://youtu.be/-wDaVLkKOiU
○ IF Statements in Python – https://youtu.be/CC5seZ6OBJ4
○ FOR Loops in Python – https://youtu.be/JgH-D5DSTho

☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course] https://youtu.be/9hvnSZPMtuw

📖 Blog: http://digital.academy.free.fr/blog/

📖 Complete Python Development Course for Beginners [PLAYLIST]: http://digital.academy.free.fr/playlist/python-development-for-beginners

🛒 Shopping and Discounts: http://digital.academy.free.fr/store/

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡
http://digital.academy.free.fr/
https://twitter.com/DigitalAcademyy
https://www.facebook.com/digitalacademyfr
https://www.instagram.com/digital_academy_fr/
https://www.youtube.com/c/DigitalAcademyOnline

♡ SUPPORT US ♡
http://digital.academy.free.fr/join
http://digital.academy.free.fr/donate
http://digital.academy.free.fr/subscribe
https://www.patreon.com/digital_academy
https://www.buymeacoffee.com/digital_academy

***

Copy link
Powered by Social Snap