What does list.insert() in actually do in python?

前端 未结 2 972
长发绾君心
长发绾君心 2021-01-24 18:26

I have code like this:

squares = []
for value in range(1, 5):
    squares.insert(value+1,value**2)

print(squares)
print(squares[0])
print(len(squares))
<         


        
2条回答
  •  盖世英雄少女心
    2021-01-24 18:49

    Basically, it's similar to append, except that it allows you to insert a new item at any position in the list, as opposed to just at the end.

提交回复
热议问题