Dictionaries in Python

Day 8 in #100DaysOfCode

Data values are stored in key: value pairs using dictionaries. A dictionary is an ordered, changing collection that does not allow duplication. Dictionaries are written with curly brackets, and have keys and values. Here is an example;

Code:

client= {
    "name":"Adam Smith",
    "age":"20",
    "is_verified":True
}
print(client["name"])

Result:

Adam Smith

We can also find out "dictionary length" with len function. Let's see another example in this case. Code:

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
print(len(thisdict))

Result:

3

Finding our type() in Python: Dictionary objects are defined as objects of the data type 'dict' in Python.

Code:

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
print(type(thisdict))

Result:

<class 'dict'>