Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is opposite of append() function in python? [duplicate]

Tags:

python

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!

like image 724
Jason Avatar asked Jan 30 '26 21:01

Jason


1 Answers

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

list.insert(0, element)
like image 171
Pierre Barre Avatar answered Feb 02 '26 09:02

Pierre Barre