How to add new keys to an already created python dictionary?

0 votes
I am learning Python. I want to know how to add new keys to an already existing dictionary. If there are multiple keys to add then can I add them all at once or one by one?
Jun 26 in Python by Arvind
• 2,960 points
30 views

1 answer to this question.

0 votes
my_dict = {'name':'Jack', 'age': 26}

my_dict['address'] = 'Downtown'  

# Output: {'address': 'Downtown', 'name': 'Jack', 'age':26}
print(my_dict)

And if you want to add multiple keys refer to the following example

x={1:2}
print(x)
d={3:4,5:6,7:8}
x.update(d)
print(x)

#output will be {1:2,3:4,5:6,7:8}
answered Jun 26 by Neel
• 3,010 points

Related Questions In Python

0 votes
1 answer

How to add a new line in Python?

You can use '\n' for a next ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
123 views
0 votes
1 answer

Add new keys to a dictionary?

>>> d = {'key':'value'} >>> print(d) {'key': ...READ MORE

answered Aug 13, 2018 in Python by Priyaj
• 56,920 points
34 views
0 votes
1 answer

How to correctly return an a dictionary as an output in zappier code using python?

David here, from the Zapier Platform team. ...READ MORE

answered Dec 3, 2018 in Python by charlie_brown
• 7,720 points
137 views
0 votes
1 answer

How to add a new Python interpreter in PyCharm?

Refer to the below screenshots: Then set a ...READ MORE

answered May 30 in Python by Shabnam
• 920 points
679 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 342 views
+4 votes
6 answers
0 votes
1 answer

How to add elements to a list in Python?

To initialize an empty list do this: new_list ...READ MORE

answered Jul 23 in Python by Neel
• 3,010 points
29 views
0 votes
1 answer

how to use urllib module in python?

If you are using Python 3.x then ...READ MORE

answered Jun 28 in Python by Neel
• 3,010 points
46 views