Semicolons in Python: Why They Exist and When to Use Them

Semicolons are allowed in Python. They let you put more than one statement on a single line. But they are not needed most of the time.

What a semicolon does

If you put a semicolon between statements, Python will treat them as separate commands. For example:

a = 1; b = 2; print(a, b)

That runs fine. It does the same work as three lines. But it makes the code harder to read.

When you might see them

People sometimes use semicolons in tiny scripts or quick one-liners. They also show up in examples pasted into a terminal. They can be handy for short, throwaway stuff. But they are rare in real projects.

They don’t change blocks

Semicolons do not replace indentation. Python uses indentation to mark blocks. For-loops, if-statements, functions — they still rely on indents and colons. A semicolon won’t affect that.

Style and readability

The official style guide, PEP 8, discourages putting multiple statements on one line. It prefers one statement per line. That makes bugs easier to spot. It also helps others read your code faster.

Quick tips

– Use them only for short experiments or quick commands.


– Avoid them in regular code. It helps others and future you.


– Remember: indentation, not semicolons, defines structure in Python.

So what should you do?

Keep semicolons as a rare tool. Use them for small, quick tasks. For readable, maintainable code, stick to one statement per line. That will make your work cleaner and easier to share.

Scroll to Top