On 02/04/2021 23:10, dn via Python-list wrote:
> When there are several items to be defined and initialised, how do you
> prefer to format the code, and why?

> (a) basic linear presentation:
> 
> resource = "Oil"
> time = 1
> crude = 2
> residue = 3
> my_list = "long"

In production code I'd almost always go with this one.
It's the only option that both keeps the variable and value
together and allows me to add an explanatory comment if
necessary.

> (e) implicit tuples:
> 
> resource, time, crude, residue, my_list = "Oil", 1, 2, 3, "long"
Occasionally, and in personal code, I'll  use this.
Although this would be about as many items I'd ever
have in one list.

But in production code, if items are related, I'd use it.
eg.
x,y = 42,50   # starting coordinates
hour,min,sec = 0,0,0  # default start time

But in both those cases I'd more likely define a variable
to be a tuple:
eg.
start = (42,50)  # starting coordinates

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to