Top Ad unit 728 × 90

Libreoffice

Libreoffice Writer

Dictionary in Python

 



Dictionary in Python


A dictionary in Python is a built-in, mutable, collection data structure that stores data in key-value pairs.

A dictionary is a collection which is ordered*, changeable and do not allow duplicates. Dictionaries are written with curly brackets, and have keys and values:


Ex.1


dict ={

  "Name": "AD Computer Campus",

  "Blog": "Python",

  "year": 2019,

}

print(dict)


Output

{'Name': 'AD Computer Campus', 'Blog': 'Python', 'year': 2019}


Ex.2


dict ={

  "Name": "AD Computer Campus",

  "Blog": "Python",

  "year": 2019,

}

print(dict[Name])


Output

AD Computer Campus


Duplicates Not Allowed


dict ={

  "Name": "AD Computer Campus",

  "Blog": "Python",

  "year": 2019,

  "year": 2022,

}

print(dict)


Output

{'Name': 'AD Computer Campus', 'Blog': 'Python', 'year': 2022}


Dictionary Length


dict ={

  "Name": "AD Computer Campus",

  "Blog": "Python",

  "year": 2019,

}

print(len(dict))


Output

3


Dictionary String, int, Boolean, and list data types:


Prog 1.


dict ={

  "Name": "AD Computer Campus",

  "Blog": "Python",

  "year": 2019,

  "colors": ["red", "white", "blue"]

}

print(dict)


Output

{'Name': 'AD Computer Campus', 'Blog': 'Python', 'year': 2019, 'colors': ['red', 'white', 'blue']}


Prog 2.


info=    {

"Name" : "Rahul",

"Subject" : ["python","C","Java"],

"Topic" : ("dict","set"),

"age" : 35,

"is _adult" : True,

"marks" : 94.6

}

print(info)


Output

{'Name': 'Rahul', 'Subject': ['python', 'C', 'Java'], 'Topic': ('dict', 'set'), 'age': 35, 'is _adult': True, 'marks': 94.6}


Dictionary in Python Reviewed by ADcomputercampus on March 06, 2026 Rating: 5

No comments:

Contact Form

Name

Email *

Message *

Powered by Blogger.