.pop()

Removes an item from a list while also returning it.

Syntax

list.pop(index)

It accepts one optional input which is the index of the element to remove. If no index is provided, then the last element in the list will be removed and returned.

Example

To pop the element 'Discrete Math' from the courses list:

Code
Output
Loading...

Example 2

If no index is provided:

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy