DEV Community

Areeb ur Rub
Areeb ur Rub

Posted on

No Need, but some use semi-colon in Python. Here's Why!

we dont do it here

Yeah, in python it's not mandatory to end a statement with semi-colon. But some people uses it because it also have a use in python.

Use of ';' in python

In python also Semi-colon is used to end a statement but what it allows is that you can continue to write the next statement in the same line.
Means if you use a ; the you don't have to change to new line you can just start with new sentence.

something like this

if this_is_bad_code: rewrite_code(); make_it_more_readable();

source: python.org

Top comments (2)

Collapse
 
moopet profile image
Ben Sinclair

You can do that, but

Sparse is better than dense.
Readability counts.

:)

Collapse
 
areeburrub profile image
Areeb ur Rub

Correct Ben, Python page also mentioned this in docs

Avoid having multiple statements on a single line.

Though the language definition allows one to use a semi-colon to delineate statements, doing so without reason makes one’s code harder to read. Typically violated with the previous rule.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay