What is the function of the semicolon in Python?
In this article you will learn the function of the semicolon in Python, rarely used and many consider unnecessary, is it?
Hey you programmer, ok? Let’s learn more about Python!
The first thing, or one of the first, taught by Python teachers is that you don’t need the semicolon to end lines.
And that is perfectly correct, the language has this particularity
But the semicolon exists in Python too, now what?
Its use is: to put two or more commands on the same line
This happens in some specific situations and should not be adopted just out of vanity 😀
Take a look:
a = 1 b = 2 c = 3 print(a); print(b); print(c)
This is the return:
1 2 3
Remembering that for other cases the semicolon is unnecessary
In Python we don’t need a terminator on the lines, totally optional
And strongly discouraged!
So be careful, especially for beginners, to use it only when there is a real need, to write a Pythonic code
In this article we learned what the semicolon function in Python
We know that in the language it is considered optional in the way that it works in others, as a line terminator
But when we want to use two commands on a line, or more, we can use this syntax which is perfectly acceptable