PEP new assert idiom
Steven Bethard
steven.bethard at gmail.com
Sun Nov 7 03:56:43 EST 2004
Fábio Mendes <niels_bohr <at> uol.com.br> writes:
>
> I never said that commas should mean line continuation (as a backslash).
> It CAN be used as implicit line continuations in lot cases, (like
> function arguments, for instance. This would be just one more case.
I'm not sure that I understand you correctly, but if you're saying that the
commas in a function argument list indicate an implicit line continuation, I
think this is probably not correct. It's the unclosed parentheses that indicate
the line continuation, not the commas -- this is why you can write a function
argument list across multiple lines, but it's also why you can write a tuple
across lines:
>>> def f(x,
... y, z):
... print x, y, z
...
>>> f(1, 2, 3)
1 2 3
>>> (x,
... y, z) = 1, 2, 3
>>> print x, y, z
1 2 3
Note that just a trailing comma definitely does not mean a line continuation:
>>> x,
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'x' is not defined
I tried to write a tuple over multiple lines here, but (because commas do not
indicate line continuations), Python thinks I want to print the value of the
tuple containing x.
Of course, unclosed brackets work the same way as unclosed parentheses:
>>> [x,
... y, z] = 1, 2, 3
>>> print x, y, z
1 2 3
Steve
More information about the Python-list
mailing list