Adding a key to the Python Dictionary

Asked 2 years ago, Updated 2 years ago, 15 views

After making dictionaries in Python, can I add keys? I don't know because I can't see the add() method.

python

2022-09-21 18:20

1 Answers

d = {1:2}
print(d)
d[2] = 3
print(d)

Or

d = {1:2}
print(d)
d.update({2:3})
print(d)

You can use it with . The results for both are as follows.

{1: 2} {1: 2, 2: 3}


2022-09-21 18:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.