How can I have one element list or tuple?

N

nico

The following example returns a string type, but I need a tuple...<type 'str'>

I need that for a method parameter.
Thx
 
S

Steven D'Aprano

The following example returns a string type, but I need a tuple...
<type 'str'>

I need that for a method parameter.
Thx


It is the comma, not the brackets, that create tuples. The brackets are
recommended for clarity, but aren't always required (except for grouping).
(1, 2, 3)

The only exception is the special case of an empty tuple, which you
create with an empty pair of brackets:

So for a one-element tuple:
('Parrot',)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top