How to convert this list to string?

R

Ron Adam

Jia said:
Hi all

I have a list like:
list [1, 2, 3]
list[1:]
[2, 3]

I want to get a string "2 3"
'[2, 3]'

How can I do that ?

thanks

Just to be different from the other suggestions...
>>> a = [1, 2, 3]
>>> str(a[1:]).strip('[]').replace(',', '')
'2 3'

By the way. It's a good idea to try not to use 'list' or other built-in names
for your own objects. Best to start with good habits so that you avoid odd hard
to find bugs later.

Cheers,
Ron
 

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

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top