Explain ""elif statement"" with example.
Answers
Answered by
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 ❤️
Please mark me as brainlist ❤️
Answered by
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
Hindi,
4 months ago
English,
4 months ago
Math,
4 months ago
Computer Science,
9 months ago
Computer Science,
9 months ago
Psychology,
11 months ago
Physics,
11 months ago