if Statement

The if statement in Python is used to check a condition.
If the condition is True, the program will execute a block of code.

It uses the keyword if.

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:
    # code to execute

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

Why if Statement is Important

  • Helps programs make decisions
  • Used in real-world applications
  • Builds logical thinking
  • Forms the base for advanced coding

Common Beginner Mistakes

  •  Missing colon (:)
  •  Wrong indentation
  •  Using = instead of ==
  • Writing invalid conditions

➤ Key Points

  • if statement checks a condition
  • Condition must return True or False
  • Uses indentation (space/tab)
  • Executes only when condition is True

➤ Tips

  • Always use colon (:) after condition
  • Keep conditions simple and readable
  • Use comparison operators (>, <, ==)
  • Practice with small examples

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