dict Data Type In Python

 If we want to represent a group of values as key-value pairs then we should go for dict data type.


Example:

d=(101:'siddu',102:'ravi',103:'chiru')


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 new value.


Example:

>>> d=(101:'siddu',102:'ravi", 103:"chiru"}

>>> d[101]='lakshmi'

>>> d

(101: 'lakshmi', 102: 'ravi', 103: 'chiru')


We can create empty dictionary as follows d=()

We can add key-value pairs as follows d['a']='apple'

d['b']='banana'

print(d)


Note: dict is mutable and the order wont be preserved.

No comments:

Post a Comment

Thank you Very Much.For Given Comment

Downloading Talliki Vandhanam List

--> Citizens can know the status of Talliki Vandhanam Click Here -->Knowing the Status of Talliki Vandhanam   --> In GSWS NBM Login...