List insert at index that is well out of range - behaves like append

前端 未结 7 838
天命终不由人
天命终不由人 2020-12-11 00:37

I had a list

 a = [1, 2, 3]

when I did

a.insert(100, 100)

[1, 2, 3, 100]

as list was originally of siz

7条回答
  •  天命终不由人
    2020-12-11 00:52

    The documentation says:

    L.insert(index, object) # insert object before index
    

    So it seems when you try inserting at index 100 it will really get the existing index on the list before 100.

提交回复
热议问题