Python List pop() Syntax
list_name.pop(index)
Parameter
- index (optional) – The value at the index is popped out and removed. If the index is not given, then the last element is popped out and removed.
Return
Returns The last value or the given index value from the list.
Exception:pop() method raises IndexError when the index is out of range.
Python List pop() Method
Python list pop() function removes elements at a specific index from the list.
Example
Python
fruits = [ "apple" , "mango" , "cherry" ] fruits.pop() print (fruits) |
Output:
['apple', 'mango']