Python Forum
insert - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: insert (/thread-12002.html)



insert - mj125 - Aug-04-2018

hello, I'm a beginner at python and I run this code:

x = [1,2,3,4]
print("x= ",x)
y = x.insert(1,6)
print("y= ", y)
and the answer is:

Output:
x= [1, 2, 3, 4] y= None
why?


RE: insert - buran - Aug-04-2018

list.insert() method works in-place, e.g.
my_list = [1, 2, 3, 4]
my_list.insert(1, 6)
print(my_list)
Output:
[1, 6, 2, 3, 4]



RE: insert - mj125 - Aug-04-2018

Thanks.