Chandu K

Chandu K

  • NA
  • 97
  • 8.5k

When we use remove() method in list and the set we get different error

Jun 29 2021 10:06 AM

A quick question using python - 
When we use remove() method in list and the set we get different error one is giving Value error and other one return key error, is there any specific reason??

s = [10,20,30,40]
s.remove(50)
print(s)

Traceback (most recent call last):
     s.remove(50)
ValueError: list.remove(x): x not in list
-------------------------------------------
s = {10,20,30,40}
s.remove(50)
print(s)

Traceback (most recent call last):
    s.remove(50)
KeyError: 50

 


Answers (2)