473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Tuple Syntax and ()

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?

Jun 13 '06 #1
2 1260
ta*******@gmail.com wrote:
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?


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/
Jun 13 '06 #2
ta*******@gmail.com wrote:
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?

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

Jun 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jinming Xu | last post by:
Hi Folks, I have a number sequence, which is put into a tuple like this: y=2, 3.0, 4.5 I can manipulate the sequence as a tuple when it has more than 1 number. But when the sequence has...
37
by: Gregor Horvath | last post by:
Hi, >>>type() <type 'list'> >>>type(('1')) <type 'str'> I wonder why ('1') is no tuple????
12
by: Kay Schluehr | last post by:
Hi all, thanks for Your attention ! I think my proposal was more in mind of Rons modified exec than Pythons lambda. When George proposed his unpacking behavoir for list-comps as a pack of...
1
by: Steve | last post by:
I have been trying to find documentation on the behavior Can anyone tell me why the first example works and the second doesn't and where I can read about it in the language reference? Steve ...
6
by: alainpoint | last post by:
Hello, I have got a problem that i can't readily solve. I want the following: I want to create a supertuple that behaves both as a tuple and as a class. It should do the following:...
3
by: Michael Yanowitz | last post by:
Hello: I am still relatively new to Python. I am confused by the syntax for tuples. I had: thread.start_new_thread(read_data_thread, (strDataFilename)) and got back the following error: ...
6
by: fdu.xiaojf | last post by:
Hi all, I can use list comprehension to create list quickly. So I expected that I can created tuple quickly with the same syntax. But I found that the same syntax will get a generator, not a...
25
by: beginner | last post by:
Hi, I am wondering how do I 'flatten' a list or a tuple? For example, I'd like to transform or ] to . Another question is how do I pass a tuple or list of all the aurgements of a function to...
21
by: Martin Geisler | last post by:
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkjlQNwACgkQ6nfwy35F3Tj8ywCgox+XdmeDTAKdN9Q8KZAvfNe4 0/4AmwZGClr8zmonPAFnFsAOtHn4JhfY =hTwE -----END PGP...
0
by: Hatem Nassrat | last post by:
on Wed Jun 13 10:17:24 CEST 2007, Diez B. Roggisch deets at nospam.web.de wrote: Well I have looked into this and it seems that using the list comprehension is faster, which is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.