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

Code
Output
Loading...

Example 2

If no index is provided:

Code
Output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy