473,226 Members | 1,696 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,226 software developers and data experts.

Difference between del and remove?

Got a quick n00b question. What's the difference between del and
remove?
Dec 13 '07 #1
4 9564

"Yansky" <th*********@gmail.comwrote in message
news:eb**********************************@e25g2000 prg.googlegroups.com...
| Got a quick n00b question. What's the difference between del and
| remove?

Python has a del statement but not a remove statement. Correspondingly,
the first is a keyword and the second is not.

tjr

Dec 13 '07 #2
On Wed, 12 Dec 2007 19:17:49 -0800, Yansky wrote:
Got a quick n00b question. What's the difference between del and remove?
Everything. list.remove(value) removes the first item equal to value.
del list[index] removes the item at position index.

See also: help([].remove)
Help on built-in function remove:

remove(...)
L.remove(value) -- remove first occurrence of value
>>alist = [101, 102, 103, 104, 105]
alist.remove(103)
alist
[101, 102, 104, 105]
>>del alist[0]
alist
[102, 104, 105]
--
Steven.
Dec 13 '07 #3
Yansky <th*********@gmail.comwrote:
>
Got a quick n00b question. What's the difference between del and
remove?
It would have been easier to answer if you had given a little context.

"del" is a Python statement that removes a name from a namespace, an item
from a dictionary, or an item from a list.

"remove" is a member function of the 'list' class that finds a specific
entry in the list and removes it.

Example:
>>e = [9,8,7,6] ; del e[2] ; e
[9, 8, 6]
>>e = [9,8,7,6] ; e.remove(2) ; e
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: list.remove(x): x not in list
>>e = [9,8,7,6] ; e.remove(8) ; e
[9, 7, 6]

Note that "del e[2]" removed item number 2 (counting from 0). e.remove(8)
removed the item that had the value 8 from the list. e.remove(2) failed
because the number 2 was not in the list.

Dictionaries do not have a "remove" method. You have to use the "del"
statement.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Dec 13 '07 #4
Thanks for the clarification guys. :)

On Dec 13, 7:05 pm, Tim Roberts <t...@probo.comwrote:
Yansky <thegoodd...@gmail.comwrote:
Got a quick n00b question. What's the difference between del and
remove?

It would have been easier to answer if you had given a little context.

"del" is a Python statement that removes a name from a namespace, an item
from a dictionary, or an item from a list.

"remove" is a member function of the 'list' class that finds a specific
entry in the list and removes it.

Example:
>e = [9,8,7,6] ; del e[2] ; e

[9, 8, 6]
>e = [9,8,7,6] ; e.remove(2) ; e

Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: list.remove(x): x not in list
>e = [9,8,7,6] ; e.remove(8) ; e

[9, 7, 6]

Note that "del e[2]" removed item number 2 (counting from 0). e.remove(8)
removed the item that had the value 8 from the list. e.remove(2) failed
because the number 2 was not in the list.

Dictionaries do not have a "remove" method. You have to use the "del"
statement.
--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
Dec 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: ambar.shome | last post by:
Can anyone tell me : 1. void main() { char temp = "Hello"; temp='K';
0
by: Shi Mu | last post by:
Is there any difference if I remove the '/' from the following statement? intMatrix2 = ,\ ,\ ] print intMatrix2 I removed one '\' and it still works. So what is the use of '\'?
10
by: Jon Davis | last post by:
I've been using the ref keyword as a way of passing strings to methods as references so that in the method I don't have to manually return the modified "version" of what was passed into the method,...
4
by: iamonthisboat | last post by:
I have a data set like so: UTC_TIME Timestamp NodeID Message Flag Line Station 11/19/2005 10:45:07 1132397107.91 1 3 5 1028 1034...
12
by: Q1tum | last post by:
Hi all, I got a problem with childNodes.length, I use the following XML for my guestbook: <?xml version="1.0" encoding="ISO-8859-1"?> <guestbook> <entry> <from>Q1tum</from>...
0
by: Beemer Biker | last post by:
I am getting different behavior with the same style depending on where I define the style. The works fine and when I move the mouse the tooltip tracks the mouse when it rolls over the fields in...
5
by: Julius | last post by:
Hej dudes, I need to calc the difference between two timestamps / dates ... For example what i need to calculate: Date 1: 2007.11.06 - 20:13:04 Date 2: 2007.11.07 - 21:13:04 Difference:...
11
by: sunnyalways4u2000 | last post by:
hello sir, Sir will please tell me the exact difference between C and advanced C...what are the extra features or funcions...etc added in this advanced one.
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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"....

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.