python-dev summary, July 16-31
Thomas Bellman
bellman at lysator.liu.se
Thu Aug 9 13:11:40 EDT 2001
pinard at iro.umontreal.ca (François Pinard) wrote:
> There is one case, however, where using parentheses with tuples is worth
> doing, and this is for long lists of tuple elements spanning more than one
> line. Parentheses combined with proper indenting help the eye at catching
> the overall structure. For short tuples that fit on a line, parentheses are
> overkill to me.
There are a couple of other occasions where you *should* use
parentheses, or you won't get what you want:
* When the tuple is an argument to a function call.
foo(1,2,3) and foo((1,2,3)) are very different things.
* When the tuple is an element in a list or another tuple.
[1,2,3,4,5,6] and [1,(2,3),(4,5),6] are very different.
* When the tuple is a key or a value in a dictionary:
{ (1,2):"one and two", "three and four":(3,4) } works, while
{ 1,2:"one and two", "three and four":3,4 } doesn't.
> for x in 1, 2, 3:
> pass
I would always write this as
for x in [ 1, 2, 3 ]:
pass
Hmm, actually, on closer consideration, I think I would write
it as
x = 3
:-)
--
Thomas Bellman, Lysator Computer Club, Linköping University, Sweden
"God is real, but Jesus is an integer." ! bellman @ lysator.liu.se
! Make Love -- Nicht Wahr!
More information about the Python-list
mailing list