Dictionaries
Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}.
Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples.
For example, with curly braces, we will define our dictionary
But the key is unique, you can not have two different values. It doesn't allow duplicates. Check as well that we have number, strings and boolean values
We can print the name if that is written properly
But when there is a Typo, another value, the result is different
it won't take either a key that doesn't exist..It will provide an error
there is another step, the "get method"
it won't show any error and we will get "none" that means, the absence of value
In this case, we will get the default value
We can update the values as well
We can add new values as well
But the key is unique, you can not have two different values. It doesn't allow duplicates. Check as well that we have number, strings and boolean values
We can print the name if that is written properly
But when there is a Typo, another value, the result is different
it won't take either a key that doesn't exist..It will provide an error
there is another step, the "get method"
it won't show any error and we will get "none" that means, the absence of value
In this case, we will get the default value
We can update the values as well
We can add new values as well
Dictionaries
Reviewed by ohhhvictor
on
May 08, 2019
Rating:
No comments: