pop() - Removes the element with the specified key

Removes the element with the specified key.

Example

Python
fish = {
    'guppy': 2,
    'zebra' : 5,
    'betta': 10
}

fish.pop('zebra')
print(f'My fish: {fish}')

Output

My fish: {'guppy': 2, 'betta': 10}

Notes

The pop() function will return the value of the item removed.

Example

Python
fish = {
    'guppy': 2,
    'zebra' : 5,
    'betta': 10
}

z = fish.pop('zebra')
print(f'I had {z} zebra fish')

Output

I had 5 zebra fish