How Can I Create and Access a Dictionary

How to Create a Dictionary in Python

To create a dictionary in Python, braces are used to enclose the entire dictionary ({ }).

We create a dictionary called student shown below:

How to Access the Elements of a Dictionary in Python

Once we have created a dictionary, we now need to know how to access the elements of the dictionary.
This is done through the general format, dictionary_name['key'].

Below is the code to access each element of the dictionary we created below:

How to Insert an Element into a Dictionary in Python

If you want to add another attribute. For example the employee's phone number,
You do not have to recreate the entire dictionary. You can simply add in this new attribute,
This is done through the general format, dictionary_name['key']= 'value'

How to Modify an Element in a Dictionary

Also, you may want to modify an existing element in a dictionary,
Again, you don't have to rewrite the whole dictionary, but just change that one element.

This is shown in the code below:

How to Delete an Element from a Dictionary

To delete an element from a dictionary in Python,
you use the del keyword followed by the element you want to delete.