How to add an item to a dictionary in Python

preview_player
Показать описание


Code from video:
*****************
employees = {1: 'michael', 2: 'eric'}
employees[3] = 'michael'
employees

Connect with us!
*****************
Рекомендации по теме
Комментарии
Автор

for a nested dictionary try this :
dct = {}
dct ["Account_1"] = {"username": "John", "password": "psw123"}

VeNoMGnG
Автор

The explanation is very simple and helped me lot. Thanks

ilhanselim
Автор

Wow.. I was stuck on such a simple task and now I can continue with my code. Thanks a lot!

laerenkruesnison
Автор

very epic ! btw this only works on python 3

oussematoussli
Автор

hey so i have a task, it said i need to make simple search engine in dictionary. can i add string to dictionary? and can i search it? really appreciate it

ahmadzakiteknikinformatika
Автор

I would like to do the same, but with the key being autogenerated

code-snippets
Автор

How would you remove a value from the dictionary if needed?

alexmejia