Skip to content

Python If Statement

Python’s if statement is used to execute a block of code only when a specific condition evaluates to True.

Syntax

# Generic version of an if statement
if condition:
# Code to execute if the condition is True
pass

Example

# Concrete example of an if statement
age = 18
if age >= 18:
print("You are eligible to vote.")
# Output: You are eligible to vote.