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]

Here is what the above code is Doing:
1. We create a list with 5 elements.
2. We try to remove the element at index 0, but there is no element at index 0.
3. We discard the element 2 from the list.
4. We print the list.

The output of the code is:

[2, 3, 4, 5]

Explanation:

1. The list has 5 elements.
2. The element at index 0 is not removed because there is no element at index 0.
3. The element 2 is discarded from the list.
4. The list is printed.