.pop()

Published May 5, 2021Updated Sep 3, 2021
Contribute to Docs

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:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

Example 2

If no index is provided:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy