Insert at first position of a list in Python

How can I insert an element at the first index of a list ? If I use list.insert(0,elem), do elem modify the content of the first index? Or do I have to create a new list with the first elem and then copy the old list inside this new one?

The best way to find out is to just run an example:

    In [1]: ls = [1,2,3]

    In [2]: ls.insert(0, "new")

    In [3]: ls
    Out[3]: ['new', 1, 2, 3]

From: stackoverflow.com/q/21939652

Back to homepage or read more recommendations: