Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tuple Syntax and ()

0 views
Skip to first unread message

tact...@gmail.com

unread,
Jun 13, 2006, 3:26:36 PM6/13/06
to
I keep accidently trying to declare t-tuples as mytuple = (myitem)

I know this doesn't work and that you need the trailing comma, but
reading something online, I just came to realize.... the parenthesises
don't have any special meaning in relation to tuples at all, do they?

James Stroud

unread,
Jun 13, 2006, 3:34:21 PM6/13/06
to

Aside from grouping, they are special to construct an empty tuple.

py> () == tuple()
True

Also, don't underestimate their relationship with tuples when it comes
to grouping:

py> a, b, c = 1, 2, 3
py>
py> a == a, b, c
(True, 2, 3)
py> a == (a, b, c)
False

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/

Steve Holden

unread,
Jun 14, 2006, 5:22:36 AM6/14/06
to pytho...@python.org
Give that (?)man a cigar! The only time the parentheses are necessary is
when you need to disambiguate - the most frequent needs are:

() for an empty tuple: there's no other way to express that without
using tuple(), and

f((a, b, ...)) to provide a single tuple argument to a function.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

0 new messages