Stoop2win
0
Q:

add key to dictionary python

d = {'key':'value'}
print(d)
# {'key': 'value'}
d['mynewkey'] = 'mynewvalue'
print(d)
# {'mynewkey': 'mynewvalue', 'key': 'value'}
21
dict[key] = value
14
d={'a': 1,'b':2,'c':3}
d['d']=100                # to add  keys and values in dicionary 
1
# 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}
1
a_dictonary = {}
a_dictonary.update({"Key": "Value"})
0
d = {'key': 'value'}
print(d)
# {'key': 'value'}
d['mynewkey'] = 'mynewvalue'
print(d)
# {'key': 'value', 'mynewkey': 'mynewvalue'}
0
dict = {'key1':'addme', 'key2':'fill_me'} 
print("Current Dict is: ", dict) 
  
# using the subscript notation 
# Dictionary_Name[New_Key_Name] = New_Key_Value 
dict['key2'] = 'for'
dict['key3'] = 'newtask'
print("Updated Dict is: ", dict) 
-1

New to Communities?

Join the community