+ 3
I'm not understanding the pop method in Python. Can some explain the function of this method and how to code for it?
pop
2 ответов
+ 7
From the Python documentation:
list.pop([i])Remove the item at the given position in the list, and return it. If no index is specified,a.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at that position. You will see this notation frequently in the Python Library Reference.)
Basically it's a way to remove an item from a list array and can be assigned to another variable if you need to perform addition tasks with this value.
Real world use for this would be like looping through a list to perform a task on each value, and that value no longer needs to be in the list so you remove it at the same time.
- 2
Pop throws an error if provided with argument.