Wednesday, January 17, 2018

Dictionary in Python

  • Created by using bracket
  • Key value pairs
  • Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces
  • Do not have any  order
Accessing Values in Dictionary
To access dictionary elements, you can use the familiar square brackets along with the key to obtain its value. 

dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print ("dict['Name']: ", dict['Name'])
print ("dict['Age']: ", dict['Age'])

dict['Name']:  Zara
dict['Age']:  7

Snapshot of some examples of Dictionary

No comments:

Post a Comment