Dictionaries in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Dictionaries in Python

How can I append an object to a dictionary!??

18th Mar 2019, 8:37 PM
محمد السعيد سرحاني
محمد السعيد سرحاني - avatar
2 Answers
+ 6
To append one item to data dictionary: data['key'] = 'value' To append two items to data dictionary: data['key1'] = 'value1' data['key2'] = 'value2' Or just one line by write data.update({'key1': 'value1', 'key2': 'value2'})
18th Mar 2019, 10:21 PM
Ameer Abdulaziz
Ameer Abdulaziz - avatar
+ 3
Different to lists, you just assign, there will be no error. d['key'] = 'value'
18th Mar 2019, 8:46 PM
HonFu
HonFu - avatar