Answers for "python how to add a new key to a dictionary"

21

add value to dictionary python

dict[key] = value
Posted by: Guest on April-30-2020
2

python how to add a new key to a dictionary

# Basic syntax:
dictionary['new_key'] = value

# Example:
d = {'a': 1, 'b': 5} # Define dictionary
d['c'] = 37 # Add a new key to the dictionary
print(d)
--> {'a': 1, 'b': 5, 'c': 37}
Posted by: Guest on September-09-2020
7

append dictionary python

>>> d1 = {1: 1, 2: 2}
>>> d2 = {2: 'ha!', 3: 3}
>>> d1.update(d2)
>>> d1
{1: 1, 2: 'ha!', 3: 3}
Posted by: Guest on May-21-2020

Code answers related to "python how to add a new key to a dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language