A task manager must remove tasks by label, by position or as a range.
What You Need to Understand
remove(value) deletes the first matching value, pop(index) removes and returns a positional element, and del deletes at a position or slice without returning it.
When to Use It
A task manager must remove tasks by label, by position or as a range.
Step-by-Step Python Example
tasks = ["email", "review", "email", "archive"]
tasks.remove("email")
removed = tasks.pop(0)
del tasks[:1]
print(removed)
print(tasks)
How the Example Works
After removing the first email, pop(0) returns review; deleting the first remaining item leaves just archive.
Example Output
review
['archive']
[10, 30]
A Second Example
Compare this smaller variation with the main example, then experiment with your own values.
values = [10, 20, 30]
del values[1]
print(values)
Important Behavior and Edge Cases
remove() raises ValueError for absent values; pop() raises IndexError for invalid indexes; del tasks deletes the name itself.
Try It Yourself
Remove the last element by pop() and compare it with del values[-1].
Common Beginner Mistakes
remove()raisesValueErrorfor absent values;pop()raisesIndexErrorfor invalid indexes;del tasksdeletes the name itself.- Overlooking how an iterable is consumed, how element positions are chosen, or whether a function creates a new list.
Key Takeaways
remove(value)deletes the first matching value,pop(index)removes and returns a positional element, anddeldeletes at a position or slice without returning it.- After removing the first email,
pop(0)returnsreview; deleting the first remaining item leaves justarchive. remove()raisesValueErrorfor absent values;pop()raisesIndexErrorfor invalid indexes;del tasksdeletes the name itself.