Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Pop() Method | Dictionary
Python Data Structures

Pop() MethodPop() Method

Dictionaries also have a pop() method that removes a key-value pair by its key and returns its value. If the specified key isn't found in the dictionary, a KeyError exception is raised.

The syntax is:

In the following example, a KeyError exception will be raised since the dictionary does not contain the key 'guava'.

Tarea

Consider this dictionary:

You need to remove the entries with the keys 1, 5, and 6 using the pop() method.

¿Todo estuvo claro?

Sección 2. Capítulo 6
toggle bottom row
course content

Contenido del Curso

Python Data Structures

Pop() MethodPop() Method

Dictionaries also have a pop() method that removes a key-value pair by its key and returns its value. If the specified key isn't found in the dictionary, a KeyError exception is raised.

The syntax is:

In the following example, a KeyError exception will be raised since the dictionary does not contain the key 'guava'.

Tarea

Consider this dictionary:

You need to remove the entries with the keys 1, 5, and 6 using the pop() method.

¿Todo estuvo claro?

Sección 2. Capítulo 6
toggle bottom row
some-alt