Posts

Showing posts with the label Python Programming Basics

Topic 14: Dictionary Data Type in Python

Image
In Python, a dictionary is one of the most powerful and flexible data types. It allows you to store data in key–value pairs , just like a real-world dictionary where words (keys) have meanings (values). Dictionaries are unordered, mutable , and indexed by unique keys , making them ideal for quick lookups and data organization. Syntax of Dictionary # Creating a dictionary my_dict = { "name": "Alice", "age": 25, "city": "Delhi" } Keys : Must be unique and immutable (e.g., strings, numbers, tuples). Values : Can be of any data type (string, list, number, etc.). Creating a Dictionary 1️⃣ Using Curly Braces {} student = {"name": "John", "roll_no": 101, "course": "B.Tech"} 2️⃣ Using dict() Constructor student = dict(name="John", roll_no=101, course="B.Tech") Accessing Dictionary Elements You can access values using their key names . stud...