Data Type Of Python In this session we will see the new data type of python which is Dictionary. 4) Dictionary:- Dictionary is a unordered collection of mutable data type. It contains key value pair enclosed in curly braces {}. Dictionary are hashable by keys. Dictionary keys should be unique and key should be immutable. That means we can use string, tuple, frozenset as a dictionary key but not list, dictionary, or other mutable types. Empty dictionary:- D = {} Dictionary with multiple elements:- D = { 'a':10, 'b':20, 'c':30 } Here the part before colon is the key and the part after colon is value like this dictionary has key value pair. Iteration:- D = { 'a':10, 'b':20, 'c':30 } For i in D: print(i) => 'a' 'b' 'c' In the dictionary only keys are hashable not values therefor when you iterate dictionary you get only keys. Hashable:- Dictionary are hashable by keys. For example:- D = { 'a...
Comments
Post a Comment