[Tutor] The magic parentheses

Alan Gauld alan.gauld at btinternet.com
Mon Jan 25 02:06:45 CET 2010


"Lie Ryan" <lie.1296 at gmail.com> wrote 

>> and used print, I thought they would be considered the same whether as 
>> a variable, or as a direct line, guess not.
> what is equivalent:
> print (a, b, c)
> 
> and
> x = a, b, c
> print x
> 
> both construct a tuple and prints a,b,c as tuple

Not quite:

>>> a = 1
>>> b = 2
>>> c = 3
>>> x = a,b,c
>>> print a,b,c
1 2 3
>>> print x
(1, 2, 3)
>>>

The first form prints multiple values the second prints the repr of a 
single tuple value. The output is different.

Alan G.




More information about the Tutor mailing list