python lost del code example
Example 1: delete all elements in list python
mylist = [1, 2, 3, 4]
mylist.clear()
print(mylist)
# []
Example 2: del vs remove python
A = [1,2,3,4]
del(A[1])
# A: [1,3,4]
B = {9,8,7,6}
B.remove("8")
# B: {9,7,6}
mylist = [1, 2, 3, 4]
mylist.clear()
print(mylist)
# []
A = [1,2,3,4]
del(A[1])
# A: [1,3,4]
B = {9,8,7,6}
B.remove("8")
# B: {9,7,6}