Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)

I just want to know, whether we can add a key to a python dictionary, once when it's created.

It doesn't appear to have an .add() function.

1 Answer

0 votes
by (26.4k points)

Try the following code:

d = {'key': 'value'}

print(d)

# {'key': 'value'}

d['mynewkey'] = 'mynewvalue'

print(d)

# {'key': 'value', 'mynewkey': 'mynewvalue'}

Join the python online course fast, to learn python concepts in detail and get certified.

Related questions

0 votes
1 answer
asked Sep 17, 2019 in Python by Sammy (47.6k points)
+1 vote
1 answer
asked May 24, 2019 in Python by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 27, 2019 in Python by Sammy (47.6k points)

Browse Categories

...