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.

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay