+ 3

Is there any method named deleteHead() for lists in python? If it exists, what is the use of this method??

Which method should I use to remove first element of list other than pop()

9th Apr 2019, 12:25 PM
RILEY
2 Réponses
+ 3
You can use del(). lst = [1,2,3] del(lst[0]) print(lst) #[2,3] If you wanted to use this in a deleteHead() function: def deleteHead(lst): del(lst[0]) Then you have: def deleteHead(lst): del(lst[0]) lst = [1,2,3] deleteHead(lst) print(lst) #[2,3] Another option (if you can't/don't want to use del()) is: lst = lst[1:] So lst = [1,2,3] lst = lst[1:] print(lst) #[2,3]
9th Apr 2019, 3:23 PM
Russ
Russ - avatar
+ 1
There does not exist a method named a deleteHead() in python 3 . We can use remove () or del method other than pop() to remove an element from the list.
27th Apr 2019, 6:33 PM
RILEY