Python If Statements & Conditions for Beginners
June 19, 2026
If statements let a program make decisions. In computer science this is called selection, and it appears all over the GCSE and A-Level specifications. This guide explains how conditions work in Python with examples you can run.
A simple if statement
age = int(input("Your age: "))
if age >= 18:
print("You can vote")
Adding else
else runs when the condition is false:
if age >= 18:
print("You can vote")
else:
print("Too young")
Several options with elif
if mark >= 70:
print("Pass with merit")
elif mark >= 50:
print("Pass")
else:
print("Fail")
Comparison operators
==equal to (note the double equals)!=not equal to<and>less than / greater than<=and>=less than or equal / greater than or equal
Combining conditions
Use and, or and not to build more complex tests:
if age >= 13 and age <= 19:
print("You are a teenager")
Common mistakes
- Using a single
=(assignment) instead of==(comparison). - Forgetting the colon at the end of the
ifline. - Incorrect indentation under the if.
Try changing the values in these examples in our free online Python IDE to see how the output changes — it is the fastest way to understand selection.
Try these conditions yourself.
Run if/elif/else examples in our free Python IDE.
Open the Python IDE →