Skip to main content
Anime study buddy

Learning outcomes

By the end of this chapter, you should be able to:
  • identify list, tuple, set, and dictionary
  • explain mutable vs immutable types
  • perform basic operations on each

List

Ordered, mutable collection.
marks = [78, 85, 91]
marks.append(88)
print(marks)

Tuple

Ordered, immutable collection.
point = (2, 5)
Use tuple for fixed records.

Set

Unordered collection of unique elements.
s = {1, 2, 2, 3}
print(s)  # {1, 2, 3}

Dictionary

Key-value mapping.
student = {"name": "Dhruv", "marks": 89}
print(student["name"])

Mutable vs immutable

  • mutable: list, set, dictionary
  • immutable: tuple, string, int, float, bool

Common operations

nums = [10, 20, 30]
print(nums[0])
print(len(nums))

student = {"name": "A", "age": 19}
student["age"] = 20
print(student)

Exam-focused points

  • list uses [], tuple uses (), set uses {} without key-value pairs
  • dictionary keys must be unique
  • sets do not preserve duplicates

Practice questions

  1. Create a list of 5 numbers and print max/min.
  2. Create a dictionary for a student with 4 fields.
  3. Convert list [1, 2, 2, 3, 3, 3] into unique values using set.