How do you use insert() in Python

2019-09-19 01:31发布

问题:

myList = ["l","r","e"]
myList.insert("x")

I know that when using insert you need two arguments ,but what is the second argument I should pass?

回答1:

The first argument is the position to insert the element. The second argument is the element.

>>> myList = ["l", "r", "e"]
>>> myList.insert(0, "a")
['a', 'l', 'r', 'e']