1d = {'key':'value'}
2print(d)
3# {'key': 'value'}
4d['mynewkey'] = 'mynewvalue'
5print(d)
6# {'mynewkey': 'mynewvalue', 'key': 'value'}
7
1# This automatically creates a new element where
2# Your key = key, The value you want to input = value
3dictionary_name[key] = value
1>>> d1 = {1: 1, 2: 2}
2>>> d2 = {2: 'ha!', 3: 3}
3>>> d1.update(d2)
4>>> d1
5{1: 1, 2: 'ha!', 3: 3}
1# Append to Dictionary in Python
2
3# Let's say we had the following dictionary:
4
5languages = {'#1': "Python", "#2": "Javascript", "#3": "HTML"}
6
7# There are two ways to add a key-and-value set to this dictionary
8
9# Number 1: By .update() method
10
11languages.update({"#4": "C#"}) # Adds a #4 key-and-value set
12
13#--------------------------------------------
14
15# Number 2: The define-key method
16
17# This is the easier one
18
19languages['#4'] = 'C#'
20
21# ^^ Just updates a key of #4 to C#, or adds it in this case
22
23