[Tutor] The magic parentheses

Lie Ryan lie.1296 at gmail.com
Sun Jan 24 08:48:43 CET 2010


On 01/24/10 17:14, David Hutto wrote:
> Hi,
> 
> This is my first post to the list, so tell me if I'm posting incorrectly.
> 
> I'm creating a script, http://python.codepad.org/mHyqbJ2z that gives the area of two circles, based on their radius, and displays the difference between the two results.
> 
> My problem is when the results are printed, I get this:
> 
> Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
> IDLE 2.6.4      ==== No Subprocess ====
>>>>
> ('Variable 2,', 490.0, 'is greater than', 'Variable 2,', 8.0, '.')
>>>>
> ('Variable 2,', 490.0, 'is greater than', 'Variable 2,', 8.0, '.')
>>>>
> ...
> The parentheses, as well as the apostrophes and commas. I'm sure it's the way I'm having the results printed after it's through, but not sure how to correct it. 
> 
> I tried writing the 'Variable 1' and '2', as well as the 'is greater
> than' within the y, and z local variables in the def return_difference_of12, and got the same result as when I
> listed the portions of the printed result's sentence in the non-local variables I have now(I'm new to Python, so I'm not sure if this would be the correct term).
> 
> Any help would be appreciated. Thanks in advance.
> 

OT: for short snippets like this, you should just paste it in the post
rather than using codepad

"""
  y = v1,var1,v3,v2,var2,period
  print y
"""
is not the same as
"""
  print v1,var1,v3,v2,var2,period
"""

the first code creates a tuple, assign it to y, then prints the tuple;
the latter prints the bunch of items separated with space.



More information about the Tutor mailing list