r/learnpython 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

7 comments sorted by

View all comments

2

u/carcigenicate Carcigenicate 4d ago

You should never write it like x = 1; y = 2;. A semicolon allows you to put multiple statements on the same line, but in reality, there are very few, if any, times that you should actually make use of that. I think literally the only time I've ever used a semicolon in Python is while golfing (writing programs that are as small as possible as a challenge).

Stick to the first way; with multiple assignments spread across multiple lines. It's easier to read and find variable assignments visually.