Posts

Showing posts with the label dictionary

What is Dictionary in Python?

 A dictionary is a data structure used to store data as key–value pairs . One is Keyword and another is Value for that keyword. Example: person = {"name": "Manoj", "age": 15, "city": "Chennai"} Values in a dictionary are accessed using keys instead of index numbers . person = {"name": "Mohan", "age": 25, "city": "Chennai"} print(person["name"]) It will print the value for the key "name" . Dictionaries are changeable (mutable) . You can update old values with new values using the key. person = {"name": "Raj", "age": 25} person["age"] = 30 print(person) A dictionary can also store different data types in the same structure . person = {"name": "Kavi", "age": 25, "height": 175.5, "is_employee": True}