← 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)withremove(value).
Practice
- Maintain to-do list with add/remove options.
- Find max, min, average from list input.