[Tutor] The magic parentheses

David Hutto dwightdhutto at yahoo.com
Mon Jan 25 03:31:05 CET 2010

Re: [Tutor] The magic parentheses
Sunday, January 24, 2010 9:28 PM
"David Hutto" <dwightdhutto at yahoo.com>
Add sender to Contacts
"Alan Gauld" <alan.gauld at btinternet.com>

--- On Sun, 1/24/10, Alan Gauld <alan.gauld at btinternet.com> wrote:

> From: Alan Gauld <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] The magic parentheses
> To: tutor at python.org
> Date: Sunday, January 24, 2010, 8:06 PM
> "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.

So 'print a,b,c' says display the values of a,b,c in the sequence of a,b,c given. 'print x' says print the value of x, x grabs a's value, b's value, and c's value, and displays the values for print.

So the sequence becomes a tuple because it's a value of values, and it's sum comes back in the form of a tuple, not an actual end variable. In other words the second leap to find the values of a,b,c for value x, makes the result printed for x(x becomes an array of other data a tuple, correct?

Now if I want to turn the first values listed under x into tuples(or use the format function that I think was named in another reply to return the non-tuple version of the value for x and I'm going to try it in a few min) of the other two variables, like below:

g = f
a = b,c
b = a,c
c = a,g
x = a,b,c

This is off the topic I think, so I'll repost under another if necessary, but how do I avoid going into the loop of tuples/variables. If a is dependent on knowing what b,c are, and b is dependent on knowing what a and c are, and c is dependent on knowing what a and b are, how do I prevent from going into a defining loop for each.

This is just basically playing with Python's functions, I was just wondering how to approach such a problem where variables must come in order but might be dependent on a following variable who's positioning is needed to maintain the hierarchy of other variables it might represent.

In the above, if I want to know c it requires knowing a,g. But in order to know a, a needs to know b,c-so I can't list c above a or a above c, because I get the error that the value of the other is not known when I try to run the script.



More information about the Tutor mailing list