Add new keys to a dictionary

0 votes

Is it possible to add a key to a Python dictionary after it has been created? It doesn't seem to have an .add() method.

Aug 13, 2018 in Python by bug_seeker
• 15,550 points
128 views

1 answer to this question.

0 votes
>>> d = {'key':'value'} 
>>> print(d) {'key': 'value'} 
>>> d['mynewkey'] = 'mynewvalue' 
>>> print(d) {'mynewkey': 'mynewvalue', 'key': 'value'}
answered Aug 13, 2018 by Priyaj
• 58,140 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,970 points
69 views
0 votes
1 answer

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

my_dict = {'name':'Jack', 'age': 26} my_dict['address'] = 'Downtown' ...READ MORE

answered Jun 26, 2019 in Python by Neel
• 3,020 points
172 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
134 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
529 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 2,477 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,810 points
1,858 views
0 votes
1 answer

Best way to create a simple python web service

web.py is probably the simplest web framework ...READ MORE

answered Jul 20, 2018 in Python by Priyaj
• 58,140 points
205 views
+1 vote
2 answers

Appending data to a file

First open the file that you want ...READ MORE

answered Jul 23, 2018 in Python by Omkar
• 69,150 points
169 views