HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Glossary
  2. /Python and data
  3. /If Statement (in Python)

What is If Statement (in Python)?

In short

An if statement runs a block of code only when a condition is true. With elif and else, it chooses between several blocks.

In simple words

The condition is a test that gives True or False, such as score >= 40. The block that belongs to the if is indented. Python checks the if first, then each elif in order, and runs the first block whose condition is true. The else block runs if none are true. Conditions can be combined with and, or and not.

Example

This prints B.

Learn it properly

  • Lessons on this topic
  • Test yourself

Related terms

  • While Loop (Repeat Until)
  • Variable (in Python)

← All glossary terms

Learn it in

  1. If, Elif, Else: Making Decisions
  2. And, Or, Not: Combining Conditions
All lessons on this topic →

Practise

  1. Write a simpler condition, without a not in front of a bracket, that is the same as each…Medium
  2. At a club door the guard asks the age first…Medium
  3. This program should say a vowel only for the letters a, e, i, o and u…Medium
The ticket price rules are: under 5 free, under 13 pays 50, under 60 pays 100, and the…Medium

Quick questions

  1. A program tests an answer, and the test has a common bug. The program also shows the…Hard
  2. A program sets a grade with two separate if statements. What does the program print?Hard
  3. A program uses chained comparisons and a mixed condition. What does the program print?Hard

More Python and data terms

  1. Cell (in a Python notebook)
  2. Class and Special Methods (in Python)
  3. Dictionary (in Python)
  4. For Loop
  5. Function (in Python)
  6. Import (Python modules and libraries)
All Python and data terms →

Try it yourself

Python labs run in your browser. Type the code, run it and see what happens.

Open a Python lab