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
• 3,050 points
754 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 in Python?

Yes, it is possible to add new ...READ MORE

answered Feb 9, 2022 in Python by Nandini
• 5,480 points
553 views
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,770 points
599 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, 2021 in Python by Reshma
953 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
1,259 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,422 views
0 votes
1 answer
+5 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,790 points
4,042 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
779 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
772 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP