1 Replies - 356 Views - Last Post: 26 October 2017 - 05:19 PM Rate Topic: -----

#1 Torroes.Prime  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 20-March 15

The difference between del and remove?

Posted 26 October 2017 - 03:12 PM

Okay, so totally new to python, this is week 4 of an 8 week class. This week we're working with lists. The methods the book has listed for working with lists (yes I am very certain there are more but in the scope of this particular class they) are:

Min and Max, del, remove, reverse, append, sort, insert, and index. So Min and max I get, it returns the min/max value contained in a list. Reverse swaps the order of the list, sort sorts it based on a given criteria, Insert adds an element at a given index, and index returns the value at a given index.

But what is the difference between del and remove? The book says, and I quote: "The remove method you saw earlier removes a specific item from a list, if that item is in the list. Some situations might require remove an element from a specific index, regardless of the item stored at that index."

So... like if I have somelist=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] and I somelist.remove[4] the updated list would be:

somelist=[0, 1, 2, 4, 5, 6, 7, 8, 9]

But what if I del somelist[4]? Would the new list be something like:

somelist=[0, 1, 2, __, 4, 5, 6, 7, 8, 9] ?

Like what's the difference between the two?

Is This A Good Question/Topic? 0
  • +

Replies To: The difference between del and remove?

#2 woooee  Icon User is offline

  • D.I.C Head

Reputation: 45
  • View blog
  • Posts: 168
  • Joined: 21-November 12

Re: The difference between del and remove?

Posted 26 October 2017 - 05:19 PM

One removes a specific item anywhere in the list, and the other deletes the item at the specific offset provided https://docs.python....structures.html Also, remove is a function so your code would throw errors.

This post has been edited by woooee: 26 October 2017 - 05:24 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1