How to Use the Semicolon in Python

Python semicolon “denotes separation, rather than termination.” It allows you to separate multiple statements on a single line.

However, it’s important to note that this is not a common practice in Python and is generally discouraged in favor of writing each statement on its own line for better readability.

Visual Representation

Use Semicolon in Python

print('Millie'); print('Bobby'); print('Brown')

Output

Millie
Bobby
Brown

Example 1: Print a semicolon

print(";")

Output

;

Example 2: Mixing Different Operations

x = 5; y = 10; z = x + y; print(z)

Output

15

Assigning a value, printing it, and then using it in another operation.

Example 3: Using with Loop

Using Semicolon with Loop

for i in range(3): print(i); print(i**2)

Output

0
0
1
1
2
4

A for loop where each iteration includes multiple operations.

Example 4: Using with List Comprehension

[print(x) for x in range(3)]; print("Loop finished")

Output

0
1
2
Loop finished

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.