Working with Lists
A list is an ordered collection of items (which can be of mixed types). Lists are defined with square brackets, e.g. fruits = ["mango", "banana", "apple"]. You can access elements by index (starting at 0): fruits[0] is "mango". Lists are mutable, meaning you can change them:
numbers = [1, 2, 3]
numbers.append(4) # now [1, 2, 3, 4]
numbers[1] = 5 # changes second element, now [1, 5, 3, 4]
Common list operations include append(), remove(), pop(), and slicing (e.g., numbers[1:3] gives [5, 3]). Lists are very handy for storing related data, like a list of student names or inventory items.
Tuples and Sets
A tuple is like a list but immutable (cannot be changed once created). Defined with parentheses: coords = (10.0, 5.0). Use tuples for fixed collections. You can index and iterate through tuples, but not append or modify items.
A set is an unordered collection of unique items, defined with braces: colors = {"red", "blue", "green"}. Since sets have no order and no duplicates, use them for membership tests or removing duplicates from a list. Example: len({"a", "b", "a"}) is 2.
Dictionaries (key–value pairs)
ProReviewer — locked
Drills, code labs, and full solutions.
Module Summary
ProReviewer — locked
Drills, code labs, and full solutions.
Practice & Exam Drills — Lesson 12
ProReviewer — locked
Drills, code labs, and full solutions.