• Skip to primary navigation
  • Skip to main content

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • HTML
    • JavaScript
    • jQuery
    • PHP
    • Python
    • SAS
    • Ruby
  • About
  • Write for Us
You are here: Home / Python / Does Python Use Semicolons? Why Python Doesn’t Use Semicolons

Does Python Use Semicolons? Why Python Doesn’t Use Semicolons

June 13, 2022 Leave a Comment

In general, Python does not use semicolons as Python is a “whitespace delimited” language.

While other programming languages require the use of semicolons to end code statements, you do not need to put a semicolon at the end of your lines of code in Python.

string_variable = "no semicolon at the end of this statement"

When learning Python for the first time, it’s possible you’ve already learned another language that required semicolons after each line of code.

In Python, you don’t need to end your lines of code with semicolons.

Python is a “whitespace delimited” language and therefore spaces and tabs are what separates blocks of code. You can read more in pep 8.

string_variable = "no semicolon at the end of this statement"

if len(string_variable) > 0:
    print("look at the whitespace")

#Output:
look at the whitespace

There are some cases where you can use a semicolon, but in general, semicolons are not used in Python code.

The Use of Semicolons in Python

There are cases where you can use semicolons in Python.

One example is if you want to create an inline if statement with multiple operations.

x = 1

if x > 0: print(x); print("hello"); print(x + x);

#Output:
1
hello
2

Another example is if you want to initialize multiple variables with variables in a single line.

x = 1; y = 2; z = 3;

In general, you shouldn’t use these as they are non-pythonic. However, if you want to use these, you won’t get an error in your code.

Hopefully this article has been useful for you to learn that Python doesn’t use semicolons.

Other Articles You'll Also Like:

  • 1.  How to Hide Turtle in Python with hideturtle() Function
  • 2.  Python Indicator Function – Apply Indicator Function to List of Numbers
  • 3.  Remove Brackets from String Using Python
  • 4.  How to Sort Numbers in Python Without Sort Function
  • 5.  pandas product – Get Product of Series or DataFrame Columns
  • 6.  Write Float to File Using Python
  • 7.  Length of Set Python – Get Set Length with Python len() Function
  • 8.  How to Group and Aggregate By Multiple Columns in Pandas
  • 9.  How to Clear Turtle Screen in Python with clear() Function
  • 10.  Truncate Decimal from Number with Python math.trunc() Function

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · The Programming Expert · About · Privacy Policy