I'm very confused about a situation. Why I cannot assign a list to a variable. Can someone explain it to me?
a =[1,2,3,4]
b = a.insert(0,1)
print(b)
the output is
None
I'm very confused about a situation. Why I cannot assign a list to a variable. Can someone explain it to me?
a =[1,2,3,4]
b = a.insert(0,1)
print(b)
the output is
None
The insert() method only inserts the element to the list. It doesn't return any value.
Adding to the replies that you got, if it is the list b that needs to be updated but not the list a, you should proceed as such:
a =[1,2,3]
b = list(a)
b.insert(1,20)
print(a, b)