if Conditional Statement
if
Statement
The if
statement evaluates a condition, and if the condition is True
, the code block inside the if
statement is executed.
Syntax:
if condition:
# code block to execute if the condition is True
Example:
x = 10
if x > 5:
print(f"{x} is greater than 5")
Output:
10 is greater than 5
Real-world Example:
Dodagatta Nihar checks if the temperature is high enough to go for a swim:
temperature = 32
if temperature > 30:
print("Dodagatta Nihar can go for a swim.")
Output:
Dodagatta Nihar can go for a swim.