Q. What are the two ways to remove something from a list? How are they different?


Answer =

del operator and pop method both are used to delete the value from list .

del is used to delete the value by slice while pop is used to delete value by particular index number and also it return the deleted value.

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Please give an example of this one

    ReplyDelete
    Replies
    1. l = [1,2,3,4,5,6,7,8,9]
      del l [ 0 : 3]
      #our list = [ 4,5,6,7,8,9 ]
      l.pop(5)
      #our list = [ 4,5,6,7,8 ]

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post