Skip to content

← Back to Python Course Foundations

Lists (Python)

Learning Objectives

  • Create and access list elements.
  • Use key list methods.
  • Apply list operations for small programs.

Example

nums = [5, 2, 9, 2]
nums.append(7)
nums.remove(2)
nums.sort()
print(nums)

Dry Run

  • Start: [5,2,9,2]
  • After append: [5,2,9,2,7]
  • Remove first 2: [5,9,2,7]
  • Sort: [2,5,7,9]

Common Mistakes

  • Removing item that does not exist.
  • Confusing pop(index) with remove(value).

Practice

  1. Maintain to-do list with add/remove options.
  2. Find max, min, average from list input.