PYTHON DICTIONARY
THIRUMURUGAN K
DICTIONARY
• Dictionaries are used to store data values in
key:value pairs.
• A dictionary is a collection which is ordered*,
changeable and does not allow duplicates.
• Dictionaries are written with curly brackets,
and have keys and values:
Create and print a dictionary:
• thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
Dictionary Items
• thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict["brand"])
Duplicates Not Allowed
• thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964,
"year": 2020
}
print(thisdict)
Accessing Items
 thisdict = {
 "brand": "Ford",
 "model": "Mustang",
 "year": 1964
 }
 x = thisdict["model"]
 Another way using get method
 x = thisdict.get("model")
Get all keys
 thisdict = {
 "brand": "Ford",
 "model": "Mustang",
 "year": 1964
 }
 x = thisdict.keys()
 print(x)
Get all values
 thisdict = {
 "brand": "Ford",
 "model": "Mustang",
 "year": 1964
 }
 x = thisdict.values()
 print(x)
Thank you!

Python dictionary

  • 1.
  • 2.
    DICTIONARY • Dictionaries areused to store data values in key:value pairs. • A dictionary is a collection which is ordered*, changeable and does not allow duplicates. • Dictionaries are written with curly brackets, and have keys and values:
  • 3.
    Create and printa dictionary: • thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } print(thisdict)
  • 4.
    Dictionary Items • thisdict= { "brand": "Ford", "model": "Mustang", "year": 1964 } print(thisdict["brand"])
  • 5.
    Duplicates Not Allowed •thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964, "year": 2020 } print(thisdict)
  • 6.
    Accessing Items  thisdict= {  "brand": "Ford",  "model": "Mustang",  "year": 1964  }  x = thisdict["model"]  Another way using get method  x = thisdict.get("model")
  • 7.
    Get all keys thisdict = {  "brand": "Ford",  "model": "Mustang",  "year": 1964  }  x = thisdict.keys()  print(x)
  • 8.
    Get all values thisdict = {  "brand": "Ford",  "model": "Mustang",  "year": 1964  }  x = thisdict.values()  print(x)
  • 9.