0
is it a difference between del, remove and pop for lists?
originally asked and answered here. https://stackoverflow.com/questions/11520492/difference-between-del-remove-and-pop-on-lists https://code.sololearn.com/c6Fv2K97ZdnS/?ref=app
2 ответов
+ 3
x = [1,2,3,4,5,6,7,8,9,10];
print (dir(x));
#print (help(x.remove));
#print (help(x.pop));
print (x);
'''
remove(...) method of builtins.list instance
L.remove(value) -> None -- remove first occurrence of value.
Raises ValueError if the value is not present.
'''
x.remove(4);
print (x);
'''
pop(...) method of builtins.list instance
L.pop([index]) -> item -- remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
'''
print (x.pop(2));
print (x);
+ 3
del removes the item at a specific index.
Example:
x = [3, 2, 2, 1]
del x[1]