+ 1
What difference between len.append and len.insert.....in python
4 Answers
+ 5
len is the name of a built-in Python function and should not be used as a variable name
+ 3
Please use search bar before asking:
https://www.sololearn.com/Discuss/892303/?ref=app
+ 3
Suppose we have a list lst. lst.append(4) will place 4 at the end of the list.
insert has 2 arguments: index and object. lst. insert(3, 'abc') will place 'abc' at index 3 of lst. If index does not exist the object will be placed at the end of the list.
0
list.append alway adds an item to the end of the list.
x.append(y) equals x[len(x):] = [y] or x = x + [y]
list.insert always adds an item to anywhere in the list increasing the following items' index by 1.
x.insert(y, z) equals x[y:y] == z or x = x[:y] + [z] + x[y:]