[Tutor] The magic parentheses
Hugo Arts
hugo.yoshi at gmail.com
Sun Jan 24 08:49:08 CET 2010
On Sun, Jan 24, 2010 at 7:14 AM, David Hutto <dwightdhutto at yahoo.com> 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.
>
>
> David
>
>
y = v1,var1,v3,v2,var2,period
print y
The first line assigns a tuple to y. The parentheses and commas is the way
tuples are printed. To avoid those, you could either pass all the arguments
directly to print, or use some string formatting instead of constructing a
tuple:
>>> a = 'this', 'is', 'a tuple'
>>> a
('this', 'is' , 'a tuple')
>>> print a
(1, 2, 3)
>>> print 'this', 'is passed', 'to print directly'
1 2 3
>>> print "this is {0}".format("formatted")
this is formatted
Hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100124/9d840aa1/attachment.htm>
More information about the Tutor
mailing list