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, 2019 in Python by Arvind
• 2,980 points
107 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, 2019 by Neel
• 3,020 points

Related Questions In Python

0 votes
1 answer

How can I add new keys to a dictionary?

d = {'key': 'value'} print(d) # {'key': 'value'} d['mynewkey'] = ...READ MORE

answered Dec 17, 2020 in Python by Gitika
• 65,870 points
25 views
0 votes
3 answers

How to add a new item to a dictionary in Python?

There is no add() , append() , or insert() method ...READ MORE

answered Jan 4 in Python by Reshma
67 views
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
439 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
• 58,100 points
86 views
0 votes
2 answers
+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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,851 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,422 views
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, 2019 in Python by Neel
• 3,020 points
95 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, 2019 in Python by Neel
• 3,020 points
206 views