2. Dictionary in Python
● Collection that is unordered, changeable and indexed.
● Items of dictionary can be accessed using the keys.
● Follows key-value pair
● Length can be found using len()
● Duplicate keys are not allowed, but duplicate values are allowed
● Keys are case-sensitive
● Nested dictionaries are also valid
3. Adding, updating, removing items from dictionary
● Using an unused key will add the key value into the dictionary.
dict[“brand”] = “Mustang”
● Using a used key as above will update the value associated with the key.
dict[“brand”] = “Suzuki”
This will change the value associated with brand key from Mustang to
Suzuki.
● Removing of key-value pair from the dictionary can be done using .pop()
method.
4. Looping through pairs in dictionary
Iterates through the keys in the list
Iterates through the values in the dictionary
Iterates through the key-value pair in the dictionary
6. global keyword
● Allows to modify the variable outside of current scope.
● Can also be used to create a new global variable from inside of the local
scope.
● Using global keyword outside of the function doesn’t have any importance.
● Is not required while printing or accessing a variable outside of the scope.