The value in the dictonary do not have any restrictions; any data type can be used here, including string, integer,any userdefined object,python object etc. However, such is not the case with keys.
Keys have some restricctions while defining them. There are two important points to be kept in mind about keys which are as follows:
1. One key in a dictonary can not have values i.e. duplicate keys are not allowed in the dictonary; they must be unique. Whenever duplicate keys are assigned values in the dictonary, the latest value is considered and stored whereas the previous one is lost.
dict={'Name':'Vihaan', 'age':31, 'Name':'Rituja'}
print(dict[Name])
#Output
Rituja
2. Keys are immutable .i.e We can use strings, integers or tuples for dictonary keys but something like ['key'] is not valid.
dict={['Name']:'Vihaan','age':31}
Traceback (most recent call last):
File "F:\Harish\Python\sample.py", line 1, in
dict={['Name']:'Vihaan','age':31}
TypeError: unhashable type: 'list'
Note that when we tried to input a key ['Name'], Python intrepreter given an error message.