+ 1

What difference between len.append and len.insert.....in python

20th Jun 2019, 7:29 AM
Esraa Mohammed
Esraa Mohammed - avatar
4 Answers
+ 5
len is the name of a built-in Python function and should not be used as a variable name
20th Jun 2019, 7:50 AM
Anna
Anna - avatar
+ 3
Please use search bar before asking: https://www.sololearn.com/Discuss/892303/?ref=app
20th Jun 2019, 7:39 AM
ΛM!N
ΛM!N - avatar
+ 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.
20th Jun 2019, 8:09 AM
Lothar
Lothar - avatar
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:]
20th Jun 2019, 9:27 AM
Seb TheS
Seb TheS - avatar