Python Tutorial
Lists, Tuples, Sets and Dictionaries
Choose the right Python collection and perform common add, read, update, loop and membership operations.
Concept
Lists are ordered and mutable, tuples are ordered and immutable, sets store unique values, and dictionaries map keys to values. Selecting the correct collection makes code simpler and clearer.
Collections can be nested and iterated. Dictionary iteration is especially useful for structured records, while sets are useful for uniqueness and fast membership tests.
Example
skills = ["Python", "SQL", "Git"]
student = {"name": "Aman", "skills": skills}
unique = {"Python", "SQL", "Python"}
print(student["name"])
print(unique)
Type the example yourself and change at least one value. Small experiments reveal syntax and behavior faster than passive reading.
Practice Tasks
- Create a list of five technologies and append one more.
- Build a dictionary for a course with title, duration and mode.
- Remove duplicate values from a list using a set.
Key Takeaways
- Use lists for ordered mutable sequences.
- Use dictionaries for key-value records.
- Use sets when uniqueness matters.
Previous
← Conditions and Loops
← Conditions and Loops