Member-only story
Common Python Bugs That Don’t Throw Errors
Logical mistakes that execute successfully but produce incorrect results
Some Python bugs do not crash your program.
There is no error message. No traceback. The code runs successfully. Yet the output is wrong.
This usually happens because Python allows certain behaviors that look correct but work differently than expected.
Let’s understand these bugs one by one.
1. Mutable default arguments
Look at the following function; at first glance, it looks completely correct. It takes an item and adds it to a list. If no list is provided, it simply uses an empty list as the default.
def add_item(item, items=[]):
items.append(item)
return itemsMost beginners expect this function to create a fresh list every time it’s called. Surprisingly, that’s not what Python does.
Now look at the output:
add_item(1) # Output: [1]
add_item(2) # Output: [1, 2]Why is this happening?
- The default list
items=[]is evaluated only once, when the function is defined. - Python reuses the same list for every function call








