if Statement

The if statement in Python is used to execute a block of code only when a specified condition becomes True.

If Statement in Python

The if statement is one of the most important concepts in Python programming.
It helps programs make decisions based on conditions.

In real life, we make decisions every day:

  • If marks are greater than 35 → student passes
  • If age is greater than 18 → eligible to vote
  • If score is greater than 100 → unlock next game level

Similarly, Python programs also use decision-making statements to execute specific code based on conditions.

The simplest decision-making statement in Python is the if statement.

What is an If Statement in Python

An if statement is a conditional statement used to check whether a condition is True or False.

  • If the condition is True, Python executes the code inside the if block.
  • If the condition is False, Python skips the block.

Why If Statements are Important

If statements are important because they help programs:

  • make decisions
  • check conditions
  • control program flow
  • build interactive applications
  • create smart systems

Without if statements, programs cannot respond differently to different situations.

Real-Time Examples of If Statements

Condition Action
If marks > 35 Display "Pass"
If age > 18 Eligible to vote
If score > 100 Unlock next level
If password is correct Login successful
If balance is sufficient Allow withdrawal

What is a Condition?

A condition is an expression that returns either:

  • True
  • False

Example:

10 > 5

Output:

True

Explanation

The program checks a condition first.

  • If the condition is True → it executes the code
  • If the condition is False → it skips the code

It is the simplest decision-making statement in Python programming.

Used when only one action is needed.

Real-Time Scenarios 

  • If it is raining → take an umbrella
  • If you are hungryeat food
  • If the light is offswitch it on
  • If homework is doneplay games
  • If battery is lowcharge phone



Syntax

if condition:
    statements

Example 1

marks = 60
if marks >= 50:
    print("You passed")

Output:

You passed

Example 2 

marks = 95
if marks > 90:
    print("Excellent!")

Output:

Excellent!

Explanation 

  • marks >= 50 → checks the condition
  • If condition is True, Python executes the code
  • Otherwise, nothing happens

Common Beginner Mistakes

Mistake Problem
Forgetting colon : Syntax error
Wrong indentation Indentation error
Using = instead of == Logical error
Mixing data types Unexpected results

Summary

The if statement in Python is used for decision making.

It checks whether a condition is True or False.

  • If the condition is True → Python executes the if block
  • If the condition is False → Python skips the block

Important concepts in if statements include:

  • conditions
  • indentation
  • colon usage
  • Boolean values

If statements are widely used in real-world applications such as games, login systems, banking software, and student result systems.

Learning if statements is one of the most important steps in Python programming.

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

What does the if statement do?

The if statement checks a condition.

Question 2

When does the if block execute?

Code runs only when condition is True.

Question 3

What is the output?

x = 10

if x > 5:
    print("Yes")

10 > 5 is True, so it prints Yes.

Question 4

What is the output?

x = 3

if x > 5:
    print("Hello")

Condition is False, so nothing is printed.

Question 5

What will happen in this code?

x = 7

if x > 10:
    print("A")
print("B")

if condition is False, so only B is printed.

Congratulations!

You've successfully mastered the knowledge check for "if Statement."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic Conditional Statements Next Topic if–else Statement