Use the reverse method when a list itself should change order. It reverses the original list in place and returns None, so assign no result and do not pass the call directly to a for loop. section 5.3.6
Reverse the list before using it
tasks = ["task1", "task2", "task3"] tasks.reverse() print(tasks) # ['task3', 'task2', 'task1'] section 4.1.1 section 5.3.6
Choose the operation according to whether the original list should change:
- Use reverse() when in-place mutation is intended. section 4.1.1
- Use reversed(tasks) when iterating backward while preserving the original list. section 5.3.2
- Avoid confusing reverse() with reversed(), just as sort() differs from sorted(). section 5.3.6
- Prefer reverse() followed by ordinary left-to-right slicing when negative-step slicing would reduce readability. section 4.1.1
tasks = ["task1", "task2", "task3"] for task in tasks.reverse(): pass
Inspect the failing pattern to see why reverse() cannot supply items directly to a for loop: the method returns None after mutating the list. section 5.3.6


