Computer Science, asked by soumyasitak2814, 9 months ago

Explain ""elif statement"" with example.

Answers

Answered by akki7181
4
The elif statement allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE. Similar to the else, the elif statement is optional.




Please mark me as brainlist ❤️
Answered by letmeanswer12
1

The elif statement allows to check multiple expressions.

Explanation:

  • The elif is short for else if. This helps us to have multiple expressions tested. If the condition for if is False, it will test the next elif block's condition and so on. If all the conditions are Incorrect, the other body will be executed.
  • Compared to the else, elif declaration is optional. Nevertheless, unlike else, for which at most one statement, there may be an arbitrary number of elif statements following an if.

Example:

  • def get_capital(country):
  •    if country == 'India':
  •        return 'New Delhi'
  •    elif country == 'France':
  •        return 'Paris'
  •    elif country == 'UK':
  •        return 'London'
  •    else:
  •        return None

Similar questions