Adding to a Dict in Python – How to Add to a Dictionary
—
Hello
A Python dictionary is like a JavaScript object – it’s a sequence of key:value pairs. So, you can create them like this:
stack_dict = { “frontend”: “JavaScript”, “backend”: “Node JS”, “markup”: “HTML and JSX”, } To access the value in the dictionary, you can do it this way: dict[key]. For example, if I want to access what the frontend key holds, I can do it like this:
print(stack_dict[“frontend”])
JavaScript
But what if you want to add another entry to the dictionary without going back to the dictionary to put it there? That’s what we are going to look at in this article. And I’m going to show you how to do it in 3 different ways.