Dictionaries in Python are unordered collections of key: value pairs. They are similar in that regard to JavaScript Objects and they follow the syntax of:
- Being enclosed by (starting and ending with) curly brackets: {}
- A dictionary is defined by assigning a variable to the curly brackets
- Each key:value pair is separated by a comma: ,
- They key can be either a string or a number
- Values can be any data type
- New keys and corresponding values can be added to an existing dictionary by using the .update method and passing a dictionary of the new key:value pairs as the argument
# Creating an empty dictionary
empty_dictionary = {}
# Creating a simple dictionary
simple_dictionary = {
'name': 'Adam',
'occupation: 'Engineer',
'age': 34,
}
# Adding a new key and value
simple_dictionary.update({'location':'Europe'})