Python Dictionary Update

Introduction to Python Dictionaries

Python Dictionary Update

🙋 Need help? Ask an expert now!

Updating a Python Dictionary

Updating a python dictionary is one of the most important components that allows us to easily use this structure in all of our coding needs. In the below example, I will do the following things:

  1. Initialize a new dictionary
  2. Add a couple of key & value pairs to the dictionary
  3. Print out the dictionary
  4. Update the dictionary
  5. Print it out again
# Initialize the Dictionary d = {} # Add a couple of key value pairs d[1] = 10 d['hello'] = 'world' d['list'] = [1,2,3,4] # Print out the Dictionary print(d) #Update the key '1' d[1] = 100 #Print out the dictionary again print(d)

Notice how the value for 1 was updated from 10 to 100.

Once you begin to use dictionaries in your code, they will begin to be easier to use. In the next couple of cards we will look at some common uses for dictionaries in python, and limitations of this data structure!

Edit Me on GitHub!