.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:

Example 2

If no index is provided:

Edit this page on GitHub

Contributors

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

Learn Python on Codecademy

Edit this page on GitHub

Contributors