Python Dictionaries

Dictionary represent the collection of elements in the form of key - value pair.Dictionary is an unordered set of key and value pair. It is a container that contains data, enclosed within curly braces.

  Dictionaries are indexed by keys, which can be any immutable type; strings and numbers can always be keys.

  Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key.

  Keys of Dictionary must be unique.


Example of creating Dictionary


# creating Dictionary
detail={'name':'John','phone':13345658,'city':'lucknow'}
print(detail)
{'name': 'John', 'phone': 13345658, 'city': 'lucknow'}
woman avatar

What we are going to learn in Data Structure