Dictionary in Python
Learning how to build a dictionary in Python is what I have done today.
When we create a key, we give it a value and when the key is called for, it returns the value that has been assigned to it.
So, for example:
Let us create a dictionary for month conversions. That is if we write out the short forms of the calendar months and define the values. The print command will run and the output would be the value that we have assigned to the key.
So,
Mar would return March
November would return November and so on.
We need not just use abbreviations alone. We can assign numbers to indicate the keys and it would give us the right result anyway. Please look at the screenshots.
Note that curly brackets are used.
So, Nov gets you November. This is an example only.
Get Mar gets you March.
What if numbers are assigned as keys, no problem at all. You still get the desired result.
What if an invalid key is entered?
Then we get None as the answer as you can see below.
All images are screenshots of work done on colab.