Important Notice:

The if Statement

The if Statement

16 views 1 min read

The if Statement :-

if statement Python का एक Conditional Statement (शर्तीय कथन) है। इसका उपयोग किसी condition को check करने के लिए किया जाता है।

यदि condition True (सही) होती है, तो if के अंदर लिखा code execute होता है।
यदि condition False (गलत) होती है, तो if के अंदर का code execute नहीं होता।

Python में if statement के अंदर लिखे code को Indentation (रिक्त स्थान) देना आवश्यक होता है। Indentation यह बताता है कि कौन-सा statement if block के अंदर है। सामान्यतः Python में 4 spaces का indentation प्रयोग किया जाता है।

English

The if statement is a conditional statement in Python. It is used to check a condition.

If the condition is True, the statements inside the if block are executed.

If the condition is False, the if block is skipped.

In Python, the code written inside an if statement must be given Indentation (spaces). Indentation indicates which statements are part of the if block. Generally, 4 spaces are used for indentation in Python.

Syntax:-

if condition:
    statement
 
Example:
 
age = 20
if age >= 18:
    print("You are an adult")

Output:

You are an adult

Because:

20 >= 18 → True
 
Shorthand if Statement :-

Python में if statement को एक ही line में भी लिखा जा सकता है। इसे Shorthand if Statement या One-Line if Statement कहा जाता है।

English

In Python, an if statement can also be written in a single line. This is called a Shorthand if Statement or One-Line if Statement.

 Syntax:

if condition: statement
 
Example:
 
number = 10
if number > 0: print("Positive Number")

Output:

Positive Number

Related Notes