Delete values from a string using the index

  • Thread starter Bruno Desthuilliers
  • Start date
B

Bruno Desthuilliers

(e-mail address removed) a écrit :
How do I delete or remove values from a list
del

or string

You can't. Python's strings are immutables.
using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

del a[0:5]
print a
 
K

koutoo

How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

Thanks.
 
?

=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=

How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

Thanks.

del a[1]
del a[-5]
 
E

Erik Jones

How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

Thanks.

--
http://mail.python.org/mailman/listinfo/python-list
>>> l = [1, 2, 3]
>>> del l[1]
>>> l
[1, 3]

Erik Jones

Software Developer | Emma®
(e-mail address removed)
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com
 
?

=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=

How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

Thanks.

If you want to do it all at once :

del a[1:4:2]
 

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,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top