471,355 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How can I have one element list or tuple?

The following example returns a string type, but I need a tuple...
>>var = ("Hello")
print type(var)
<type 'str'>

I need that for a method parameter.
Thx

Nov 1 '07 #1
2 11187
On 2007-11-01, nico <ni************@gmail.comwrote:
The following example returns a string type, but I need a tuple...
>>>var = ("Hello")
print type(var)
<type 'str'>

I need that for a method parameter.
var = "hello",

--
Neil Cerutti
Nov 1 '07 #2
On Thu, 01 Nov 2007 09:21:40 -0700, nico wrote:
The following example returns a string type, but I need a tuple...
>>>var = ("Hello")
print type(var)
<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
(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",
('Parrot',)

--
Steven.
Nov 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Yomanium Yoth Taripoät II | last post: by
4 posts views Thread by GrelEns | last post: by
2 posts views Thread by Ishwar Rattan | last post: by
3 posts views Thread by Dirk Hagemann | last post: by
8 posts views Thread by Captain Dondo | last post: by
reply views Thread by Hatem Nassrat | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.