dict[key] = value
# Basic syntax:
dictionary['new_key'] = 'new_value'
# Example usage:
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}
key = "somekey"
a.setdefault(key, [])
a[key].append(2)
#adding new key in python
List_of_Students = {"Jim" : "Roll-32"+","+ "Priority-First",
"Yeasin": "Roll-33"+","+ "Priority-2nd",}
List_of_Students.update({"Pinky": "Roll-34"})
for x in List_of_Students:
print(x)
#That will show only the the key
diction = {'key':'value'}#Adding a dictionary called diction.
print(diction)
diction['newkey']='newvalue'#Adding the newkey key to diction with its value.
print(diction)
#output: {'key':'value','newkey':'newvalue'}
{'Dartmoor': ['moss', 'bog', 'orchids'], 'Exmoor': ['heather', 'gorse'], 'PeakDistrict': ['orchids', 'knapweed', 'moss']}
d = {'key': 'value'}
print(d)
# {'key': 'value'}
d['mynewkey'] = 'mynewvalue'
print(d)
# {'key': 'value', 'mynewkey': 'mynewvalue'}