Dictionary declaration
Dictionary declaration
• 2.Empty Dictionary
• D={ }
• 3. The function dict() is used to create a dictionary with no items
• D=dict()
• keys() - returns an iterable of all keys in the dictionary in the form of list.
• values() - returns an iterable of all values in the dictionary in the form of list.
• items() - returns an iterable list of (key, value) tuples i.e in the form of list of
tuples..
Example of Dictionary
dict = {'name': ‘Ram','code':1234, 'dept': ‘KVS'}
print(dict) # Prints complete dictionary
print(dict.keys()) # Prints all the keys
print(dict.values()) # Prints all the values
print(dict.items())
Output:
{'dept': 'KVS', 'code': 1234, 'name': 'Ram'}
['dept', 'code', 'name']
['KVS', 1234, 'Ram']
[('dept', 'KVS'), ('code', 1234), ('name', 'Ram')]
there is a second way to declare a dict: