Python if Condition
The if statement is used to execute a block of code only if a specified condition is true. It helps your program make decisions and control the flow of execution.
Syntax:
if condition:
# code to execute if condition is True
- The condition is an expression that evaluates to either
TrueorFalse. - The code block inside the
ifstatement must be indented (usually 4 spaces). - If the condition is false, the block is skipped.
Example 1: Simple if
age = 18
if age >= 18:
print("You are an adult.")
Output:
You are an adult.
Here, the message prints only if age is 18 or older.
0
likes
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
