Answers for "discard vs remove python"

6

remove element form set in python

list1 = {1,2,3,4}
list1.remove(4)
print(list)
# {1,2,3}
Posted by: Guest on May-17-2020
2

remove an item from a set python

list.discard(item)
Posted by: Guest on May-17-2020
0

discard vs remove python

list = [1, 2, 3, 4, 5]
list.remove(0)	#removes element in specified position
print(list)
>> [2, 3, 4, 5]
list.discard(2)	#discards element if found in iterable (in list in this case) ;)
print(list)
>> [3, 4, 5]
Posted by: Guest on October-08-2021

Python Answers by Framework

Browse Popular Code Answers by Language