1d = {'key':'value'}
2print(d)
3# {'key': 'value'}
4d['mynewkey'] = 'mynewvalue'
5print(d)
6# {'mynewkey': 'mynewvalue', 'key': 'value'}
7
1dict_1 = {"1":"a", "2":"b", "3":"c"}
2dict_2 = {"4":"d", "5":"e", "6":"f"}
3
4dict_1.update(dict_2)
5print(dict_1)
6#Output = {"1":"a", "2":"b", "3":"c", "4":"d", "5":"e", "6":"f"}
1default_data = {'item1': 1,
2 'item2': 2,
3 }
4
5default_data.update({'item3': 3})
6# or
7default_data['item3'] = 3
1mydict = {'score1': 41,'score2': 23}
2mydict['score3'] = 45 # using dict[key] = value
3print(mydict)
1testing1={'one':1,'two':2}
2''' update() is the method of dict() merges another dict into existing ones '''
3''' it replaces the keys of exisiting ones with the the new ones '''
4testing1.update({'two':3,'noice':69})
5print(testing1) """ {'one':1,'two':3,'noice':69} """
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