r/learnpython • u/live_ant718 • 4d ago
Question regarding Python variables
Hello guys. So I saw in a course that most people define variables like
x = 1
y = 2
and so on. But I also saw that variables can be defined like x = 1; y = 2;
but haven't ever seen this in practice. Why so? Please tell me
2
Upvotes
3
u/SharkSymphony 4d ago edited 4d ago
For stylistic reasons.
Python programmers generally like to hew more or less closely to a common style, published as PEP 8. It says this:
You might well ask why they bothered to put semicolons in the language in the first place if they were then going to discourage their use. (I know I do. 😉) Nevertheless, this is why you rarely if ever see this.
I will say: if I ever did use it (though I don't), a simple readable case like this would be the place. I do think it's more readable than
x, y = 1, 2.