Remove an item from a list given its index instead of its value: the del statement : Del « Buildin Function « Python






Remove an item from a list given its index instead of its value: the del statement

Remove an item from a list given its index instead of its value: the del statement
# Unlike the pop()) method which returns a value, the del keyword is a statement and 
# can also be used to remove slices from a list (which we did earlier by assignment 
# of an empty list to the slice).

a = [-1, 1, 66.25, 333, 333, 1234.5]
del a[0]
print a

del a[2:4]
print a

# del can also be used to delete entire variables:
a = [-1, 1, 66.25, 333, 333, 1234.5]

del a

           
       








Related examples in the same category