Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What does "elif" does in python 3.

–5 votes
asked Dec 20, 2020 by Unique Ghimire (140 points)

3 Answers

0 votes
answered Dec 20, 2020 by Vincent Houet (140 points)

This is what we call a "syntax sugar". In fact, elif replace

else:

    if ...:
        (command)

it is used because, if there is some other conditions, your code will became

if ... :

   (command)

else:

   if ... :

      (command)

   else:

      if ... :

         (command)

      else:

           if ... :

              (command)

which is very difficult to read. So, all of this could be replaced by :

if ... :

   (command)

elif ... :

   (command)

elif ... :

   (command)

elif ... :

   (command)

elif is used to make the code more "beautifull" and easy to read for you or other developers

(sorry for my bad english smiley)

0 votes
answered Jan 6 by Pallabesh Maharana (450 points)

elif stands for else if. This is a keyword in python, used in else if conditions. 

Note:->     ':' (colon) sign is necessary after giving condition for elif.

Syntax:- 

elif condition:

statement

For more clarity click this link.

 https://www.w3schools.com/python/gloss_python_elif.asp#:~:text=The%20elif%20keyword%20is%20pythons,%2C%20then%20try%20this%20condition%22.

+1 vote
answered Jan 28 by Jeff The Chicken (2,860 points)
An elif makes the program check for a second condition if the first condition is not met.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...