Creation and use of dictionaries in Python

A dictionary is another type of container in Python, like lists and tuples, but this one has elements in pairs, these are called items, each key is separated from it’s value by a colon, each item is separated by commas and the dictionary is enclosed with {}.

To update a specific item in the dictionary, you type the name of the dictionary, after that the name of the item inside brackets and (”), then equaling this to the value you want to update it to.

The same goes for adding another item to the list, follows the same process and syntaxes.

Finally, to print the dictionary you just put it after the print function with parenthesis. In case you want to print only a specific item you need to type the name of the dictionary then the item you want to print, of course in this form [‘item’], and the whole thing goes between parenthesis as well.

Here’s an example:

Creation and use of dictionaries in Python

Creation and use of dictionaries in Python

CC BY 4.0 Creation and use of dictionaries in Python by tywins is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.