Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference with Python statements ending with ;? [duplicate]

What's the difference with Python statements ending with ; and those does not?

like image 239
MezzanineLearner Avatar asked Dec 24 '22 00:12

MezzanineLearner


2 Answers

There is really no difference. Python ends a line of code at the end of the logical line, or when it encounters ;

The only advantage to using ; is that you can stack multiple logical lines into one physical line. For example (in python3):

import sys

for i in range(10):
    print(i, end=' '); sys.stdout.flush()

That said, this is terrible coding style, so don't ever do it

like image 124
inspectorG4dget Avatar answered Dec 26 '22 14:12

inspectorG4dget


Semicolons serve the same purpose as the newline character. It is really just bad style to use a semicolon, often from people coming from languages where lines require it.

like image 25
Phoenix Avatar answered Dec 26 '22 14:12

Phoenix