The if...elif...else Statement :-
if...elif...else statement Python का एक Conditional Statement (शर्तीय कथन) है। इसका उपयोग multiple conditions (एक से अधिक conditions) को check करने के लिए किया जाता है।
सबसे पहले if की condition check होती है। यदि if condition True (सही) होती है, तो उसका code execute होता है और बाकी conditions को check नहीं किया जाता।
यदि if condition False (गलत) होती है, तो Python elif की condition को check करता है। आवश्यकता के अनुसार एक से अधिक elif statements का उपयोग किया जा सकता है।
यदि सभी if और elif conditions False होती हैं, तो else block का code execute होता है।
Python में if, elif और else के अंदर लिखे code को Indentation (रिक्त स्थान) देना आवश्यक होता है। Indentation यह बताता है कि कौन-सा statement किस block के अंदर है। सामान्यतः Python में 4 spaces का indentation प्रयोग किया जाता है।
English
The if...elif...else statement is a conditional statement in Python. It is used to check multiple conditions.
First, the if condition is checked. If the if condition is True, its block is executed and the remaining conditions are not checked.
If the if condition is False, Python checks the elif condition. Multiple elif statements can be used when required.
If all the if and elif conditions are False, the else block is executed.
In Python, the code written inside the if, elif, and else blocks must be given Indentation (spaces). Indentation indicates which statements belong to each block. Generally, 4 spaces are used for indentation in Python.
Python में if...elif...else को सामान्य if...elif...else की तरह सीधे एक ही line में लिखने का standard shorthand syntax नहीं है। लेकिन Conditional Expression का उपयोग करके simple conditions को short form में लिखा जा सकता है।
EnglishA normal if...elif...else statement does not have a direct one-line shorthand syntax. However, a Conditional Expression can be used to write simple conditions in a shorter form.