+ 2
Pop method in python
A=[1,2,3,4] Last =A.pop() print(Last) Why am I getting 4 and not a list[1,2,3] Because pop removes the element and the list stays
3 ответов
+ 8
List.pop() method is used to remove and print the last element of the list.
Now A= [1,2,3,4]
Last = A.pop()
Now A.pop() returns the last element and thereafter removes it.
So Last = 4
And then print(Last) prints 4
Thanks
+ 5
If there are any items in the list and if you use no additional arguments, list.pop method does 2 things:
list.pop removes the last item from the list in-place and returns the removed item.
+ 3
Run this code and you will see that '4' is removed:
A=[1,2,3,4]
Last =A.pop()
print(A)