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,350 points
30 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
• 56,900 points

Related Questions In Python

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 in Python by Neel
• 3,010 points
25 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
104 views
0 votes
1 answer

Convert dictionary keys to a list

list.(dictionary.keys()) READ MORE

answered Jun 28, 2018 in Python by Hamartia's Mask
• 1,580 points
36 views
0 votes
1 answer

Convert the keys of a dictionary to list

Unpacking with * works with any object ...READ MORE

answered Feb 6 in Python by Omkar
• 67,620 points
28 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 277 views
+4 votes
6 answers
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
• 56,900 points
36 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
• 67,620 points
33 views