Category: Python

Python – Set Exercises

Exercise 1: Create a Set Question Create a set of fruits and print it. Solution fruits = {“apple”, “banana”, “orange”} print(fruits) Exercise 2: Remove Duplicate Values Question Remove duplicates from a list using a...

Python Dictionaries

1. What is a Dictionary? A dictionary is a collection of data stored as key : value pairs. In simple words: 👉 A dictionary is like a real dictionary Word → Meaning Key →...

Python – Access Dictionary Items

1. What Does “Access Dictionary Items” Mean? Accessing dictionary items means getting values from a dictionary using keys. Remember: 👉 Dictionaries use keys, not index numbers. 2. Access Item Using Key Name The easiest...

Python – Change Dictionary Items

1. What Does “Change Dictionary Items” Mean? Changing dictionary items means updating the value of an existing key. In simple words: 👉 We change value, not the key. 2. Change Value Using Key Name...

Python – Add Dictionary Items

1. What Does “Add Dictionary Items” Mean? Adding dictionary items means putting new key–value pairs into a dictionary. In simple words: 👉 We add a new key with its value. 2. Add Item Using...

Python – Remove Dictionary Items

1. What Does “Remove Dictionary Items” Mean? Removing dictionary items means deleting key–value pairs from a dictionary. In simple words: 👉 We remove the key and its value together. 2. Remove Item Using pop()...

Python – Loop Dictionaries

1. What Does “Loop Dictionaries” Mean? Looping a dictionary means going through its data one by one. A dictionary has: Keys Values Key–Value pairs We can loop through all of them. 2. Loop Through...

Python – Copy Dictionaries

1. What Does “Copy Dictionary” Mean? Copying a dictionary means creating a new dictionary with the same data. This is useful when: You want to change one dictionary But keep the original dictionary safe...

Python – Nested Dictionaries

1. What is a Nested Dictionary? A nested dictionary means a dictionary inside another dictionary. In simple words: 👉 One dictionary stores another dictionary as its value. 2. Why Use Nested Dictionaries? We use...

Python Dictionary Methods

1. What are Dictionary Methods? Dictionary methods are built-in functions that help us work easily with dictionaries. They help us to: Add items Remove items Access data Copy dictionaries 2. get() – Get Value...