473,289 Members | 1,840 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,289 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 11292
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Yomanium Yoth Taripoät II | last post by:
HI, 1) what are the differences between list and tuple? 2) how to concatenate tuple and list? no method, no opérator? 3) im looking the fucking manual, and cant add value in my tuple, when it...
4
by: GrelEns | last post by:
hello, i wonder if this possible to subclass a list or a tuple and add more attributes ? also does someone have a link to how well define is own iterable object ? what i was expecting was...
2
by: Ishwar Rattan | last post by:
I am a little confused about a list and a tuple. Both can have dissimilar data-type elements, can be returned by functions. The only difference that I see is that list is mutable and tuple is...
11
by: vdavidster | last post by:
Hello everyone, I want to convert a tuple to a list, and I expected this behavior: list(('abc','def')) -> list(('abc')) -> But Python gave me this behavior: list(('abc','def')) ->
3
by: Dirk Hagemann | last post by:
Hi! I have a list of lists and in some of these lists are elements which I want to change. Here an example: lists= 'None' should be replaced by 0 or NULL or something else. But as far as I...
8
by: Captain Dondo | last post by:
I have an array(?) (sorry, I'm new* to python so I'm probably mangling the terminology) that looks like this: I want to replace every instance of 'tooth.seiner.lan' with 'localhost'. There...
11
by: rh0dium | last post by:
Hi all, I have a simple list to which I want to append another tuple if element 0 is not found anywhere in the list. element = ('/smsc/chp/aztec/padlib/5VT.Cat', '/smsc/chp/aztec/padlib',...
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...
10
by: TP | last post by:
Hi everybody, I have a question about the difference of behavior of "len" when applied on tuples or on lists. I mean: $ len( ( 'foo', 'bar' ) ) 2 $ len( ( 'foo' ) ) 3 $ len( )
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.