[Tutor] The magic parentheses

spir denis.spir at free.fr
Mon Jan 25 12:31:02 CET 2010


On Mon, 25 Jan 2010 01:06:45 -0000
"Alan Gauld" <alan.gauld at btinternet.com> wrote:

> 
> "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.

Lie's example actually was:

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

Both output values are tuples.

Denis
________________________________

la vita e estrany

http://spir.wikidot.com/


More information about the Tutor mailing list