Appending Values to a Dictionary


☞ To add a new item to the existing dictionary, extend it with a single pair of values.

Syntax :
 
<dictionary_name> [<key>] = value
Example :
 
D = {10:"Ten", 20:"Twenty"}
print(D)
D[30] = "Thirty"
print(D)
Output :
 
{10: 'Ten', 20: 'Twenty'}
{10: 'Ten', 20: 'Twenty', 30: 'Thirty'}
NOTE : We cannot concatenate two dictionary using + operaor, it will give you an error : TypeError: unsupported operand type(s) for +: 'dict' and 'dict'