Python Dictionaries: Key-Value Pairs and Data Storage

 PYTHON JOURNEY - Day 37 / 50..!! TOPIC – Python Dictionaries Today I explored Dictionaries — one of the most powerful and widely used data structures in Python. Unlike lists, dictionaries store data in Key:Value pairs! 1. Creating a Dictionary Think of it like a real-life dictionary: you look up a Word (Key) to find its Meaning (Value). Python student = { "name": "Srikanth", "course": "Python", "day": 37 } print(student["name"]) # Output: Srikanth 2. Adding & Updating Data Dictionaries are mutable, meaning you can change them easily. Python # Adding a new key-value pair student["status"] = "Learning" # Updating an existing value student["day"] = 38 3. Dictionary Methods Useful ways to extract information from your dictionary. Python print(student.keys()) # Gets all keys print(student.values()) # Gets all values print(student.items()) # Gets both in pairs Why Use Dictionaries? Fast Lookups: You don't need to know the index; just the name of the key. Organized Data: Perfect for representing real-world objects (like a user profile or a product's details). Readable: It makes your code look much more intuitive. Mini Task Write a program that: Creates a dictionary for a Smartphone (Brand, Model, and Price). Updates the price of the phone. Adds a new key called "Color". Prints the final dictionary using an f-string. #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories