What's the difference with Python statements ending with ; and those does not?
Asked
Active
Viewed 440 times
3
-
4Those ending in `;` are usually written by people who don't realize it isn't necessary. – chepner Oct 07 '16 at 03:14
2 Answers
7
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

inspectorG4dget
- 110,290
- 27
- 149
- 241
2
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.

Phoenix
- 1,553
- 2
- 13
- 29