Skip to content

Python Else Statement

The else statement in Python allows you to execute a block of code when the condition in the if statement is not met.

Syntax

# Generic version of if-else statement
if condition:
# Code to execute if the condition is True
pass
else:
# Code to execute if the condition is False
pass

Example

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