Dictionary - Python for Absolute Beginners course

Опубликовано: 13 Май 2022
на канале: Programming With Nick
376
19

In this Python for beginners tutorial we are going to learn the following:
How to create a Dictionary
How to add items to a Python Dictionary
How to remove items from a Dictionary
How to modify items from a Dictionary and so on.

A dictionary is a collection of key-value pairs. Each key is associated with a value, and you can use that key to get the value associated with that key.
Consider it similar to your standard dictionary. You search for a term, and the dictionary returns a sentence that defines that word. Python uses a key, which can be a word or a number, to obtain a value from the dictionary. That value can be anything, an Int, a Float, a String, or even a list of values!
A dictionary is similar to a list. We store values in lists and access them using their index. We don't use an index in dictionaries; instead, we use a key like this. So, each key gives us access to a value in the dictionary. As a result, dictionaries are quite useful.
Now let’s create our first dictionary.
To create a dictionary, we give it a name. Let’s create a dictionary called age to hold the age of a person as the value and the name of each person as the key.
age = curly bracket {}
With this command, I created an empty dictionary. Let’s add some key-value pairs to it.