I want to remove a value from a list if it exists in the list (which it may not).
a = [1, 2, 3, 4] b = a.index(6) del a[b] print(a)
The abov
You can do
a=[1,2,3,4] if 6 in a: a.remove(6)
but above need to search 6 in list a 2 times, so try except would be faster
try: a.remove(6) except: pass