I was just reading a presentation on python and I noted that the author had missed out the round brackets of the tuple for the items to iterate over, and it struck me that I might be inclined to leave them in. A quick re-read of PEP-8 gave no definitive answer, and I didn’t want to ‘fall-back’ on the old “explicit is better than implicit” without some discussion; so …
Which do you prefer? Which do you think is more pythonic in these two equivalent for statements (limit the discussion to its use in for statements).
>>> # Some setup
>>> x, y, z = 1, 'Hi', True
>>>
>>> #Style 1: Implicit tuple
>>> for i in x, y, z:
print(i)
1
Hi
True
>>> # Style 2: Explicit tuple
>>> for i in (x, y, z):
print(i)
1
Hi
True
>>>
I’d go with Style 2, as you can actually understand what you are iterating over:
Style 1 seems a bit confusing to me for some reason.