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
• 14,970 points
16 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,120 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
22 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
18 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
• 65,840 points
14 views
0 votes
1 answer

How do you add a background thread to flask in Python?

The example below creates a background thread ...READ MORE

answered Nov 19, 2018 in Python by Nymeria
• 3,500 points
2,754 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
20 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,120 points
18 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
• 65,840 points
21 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.