Q. What is a key-value pair in dictionary?
Answer:-
Dictionaries are simply another type of collection in Python, but with a twist. Rather than having an index associated with each data-item (just like in lists or strings), Dictionaries in Python have a "key" and a "value of that key". That is, Python dictionaries are a collection of some key-value pairs.
For example:-
Just like in English dictionaries you can search for a word's meaning, because for each word, there is a meaning associated with it. In the same manner, Python dictionaries have some keys (just like English dictionaries have words) and associated values (just like English dictionaries have associated meanings for every word).
• Dictionaries are containers that associate keys to values. This is, in a way, similar to lists. In lists, you must remember the index value of an element from the list, but with the case of dictionaries, you'll have to know the key to find the element in the dictionaries.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )