Loading...
Python

dict Data Type:

To represent group of values as key value pairs dict data type is used.

Example:
d={101:”Rahul’,201:’Raju’,301:’Rakesh’}

Duplicate keys are not allowed but values can be duplicated. If we are trying to insert an entry with duplicate key then old value will be replaced with the new values.

Example:
>>>d={101:’Rahul’,201:’Raju’,301:’Rakesh’}
>>>d[101=’Rama’
>>>d
{101:’Rama’,201:’Raju’,301:’Rakesh’}

We can create empty dictionary as follows
d={}
We can add key value pairs as follows
d=[‘a’]=’apple’
d[‘d’]=’banana’
print{d)

Leave a Reply

Your email address will not be published. Required fields are marked *