2

Recently I was learning python,and I want to use the function that is opposite of append() function.How can I use the function insert an element in the first position of the list.Thank you!

Jason
  • 49
  • 1
  • 1
  • 6
  • 1
    Is a function that inserts an element in the first position of a list really the opposite of `list.append()`? Wouldn't the opposite be something like, "remove the last element from a list and return it"? The more clearly you ask your question the more likely you are to get a good answer. – ChrisGPT was on strike Apr 25 '16 at 15:52

1 Answers1

15

Prepend doesn't exist, but you can simply use the insert method:

list.insert(0, element)
Pierre Barre
  • 2,174
  • 1
  • 11
  • 23