Okay, let's start with another very important data type that you need for your Python adventure. And that is dictionaries. A dictionary is an unordered set of key value pairs separated by comma, and enclosed by curly braces. They are very useful for storing information in a specific format. For instance, considering the router, we can store data about the device in the following format, like this using pairs consisting of a key and a value. dictionaries are immutable, which means we can modify their contents using dictionary specific procedures.
Why do I say dictionary specific because unlike strings or lists, dictionaries are not indexed by the position of each element, like we previously had. Zero for the first element, one for the next element and so on. dictionaries are indexed by key by this value right here. The key is the value on the left side of the colon of each key value pair. We will see this in practice, so don't worry. For now, let's just create an empty dictionary.
Let's say we have dict one equals open and close curly braces. Let's see dict one and type of the one. And indeed, we have class dict, which stands for dictionary. Now, let's create a dictionary with some data into it because an empty dictionary is no fun at all. So let's consider dict one again. As you can see, each dictionary elements consists of a key, a colon, and a value, followed by comma.
Now let's notice a few things here. First, because the keys in our dictionary are actually strings, as you can see right here, each key is enclosed by quotes, either double quotes or single quotes. Strings may be the most widely spread data type use for a dictionary key. You may also use a number is a key in order to have some sort of A numbering system like this one. Here, we used a number, an integer as a dictionary key for each key value pair. Now getting back to our dictionary dict one.
Another thing to keep in mind here is that although when you create a dictionary, you specify the key value pairs in a certain order, like we have vendor than a model than the iOS and then the ports. When you print out the dictionary, this order can be slightly modified. Because as I said, dictionaries are unordered set of key value pairs. Don't worry, dictionaries are not so chaotic though. Python helps us keep things smooth and clean when using dictionaries. We will see how it does that in the next lecture.
Another key thing to remember is that each key in the dictionary must be unique and should be of an immutable type. This means you can have strings, numbers or topples is keys, but not least, on the other hand values Don't have to be unique and can be either have an immutable or immutable data type. Having that said I will see you in the next lecture where we are going to dive deeper into this topic.