• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
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.  Using Python to Calculate Sum of List of Numbers
  • 2.  Drop Last Row of pandas DataFrame
  • 3.  Open Multiple Files Using with open in Python
  • 4.  pandas ewm – Calculate Exponentially Weighted Statistics in DataFrame
  • 5.  Python tan – Find Tangent of Number in Radians Using math.tan()
  • 6.  pandas Drop Columns – Delete Columns from a DataFrame
  • 7.  Using Python to Read File Character by Character
  • 8.  Using Lambda Expression with max() in Python
  • 9.  Print Object Attributes in Python using dir() Function
  • 10.  Check if a Number is Divisible by 2 in Python

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 *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

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

x