Remove Item from Dictionary in Python Tutorial Example

27-Jan-2023

.

Admin

Remove Item from Dictionary in Python Tutorial Example

Hi Dev,

If you need to see example of remove item from dictionary in python tutorial example. step by step explain how to remove from python dictionary. let’s discuss about how to remove entry from dictionary python. We will use how to remove item from dict python.

There are several ways to remove items from a dictionary in python. i will give you four examples using pop(), popitem(), del and using value in python.

Example 1: Python Dictionary Remove Item using pop()


main.py

user = {

"ID": 1,

"name": "Piyush Kamani",

"email": "piyush@gmail.com"

}

# Remove Item from dictionary

user.pop("email")

print(user)

Output:

{

'ID': 1,

'name': 'Piyush Kamani'

}

Example 2: Python Dictionary Remove Item using popitem()

main.py

user = {

"ID": 1,

"name": "Piyush Kamani",

"email": "piyush@gmail.com"

}

# Remove Item from dictionary

user.popitem()

print(user)

Output:

{

'ID': 1,

'name': 'Piyush Kamani'

}

#Python