TypeError: 'dict' object is not callable
TypeError: 'dict' object is not callable in Python means you tried to call a dictionary like a function with parentheses (), or a variable named dict shadowed the built-in dict type.
How do I fix TypeError: 'dict' object is not callable?
To fix TypeError: 'dict' object is not callable in Python, locate the line causing the error and check the values right before it runs. Most occurrences happen because of accessing a dictionary key with parentheses. Apply a defensive check or safe fallback, make sure collections or objects exist before access, and verify return values from upstream functions.
What does TypeError: 'dict' object is not callable mean?
Parentheses () in Python mean "execute this function". Dictionary lookups require square brackets [key] or the .get(key) method. When you write my_dict("key"), Python thinks you are attempting to invoke the dictionary as a callable object.
Why does TypeError: 'dict' object is not callable happen?
1. Accessing a dictionary key with parentheses
Lookups use square brackets ["key"], not round parentheses ("key").
Breaks
user = {"name": "Alice", "age": 30}
name = user("name")Works
user = {"name": "Alice", "age": 30}
name = user["name"]2. Overwriting the built-in dict function
Assigning to a variable named dict overrides the constructor.
Breaks
dict = {"a": 1}
copy = dict([("b", 2)])Works
my_dict = {"a": 1}
copy = dict([("b", 2)])3. Missing an operator or method call
A missing method name between a dictionary and arguments looks like a call.
Breaks
val = data("items", 0)Works
val = data.get("items", 0)How to find it in your own code
Replace parentheses () with square brackets [] when looking up dictionary keys, and rename any variable named `dict` to something descriptive like `user_data` or `config`.
Try it: fix this bug
easyformat_price(5) crashes: TypeError: can only concatenate str (not "int") to str.
def format_price(amount):
return "$" + amountMore challenges with this error
Each of these challenges runs into this error or pattern. Find the bug and fix it in your browser โ no install, no account needed.
Still not sure why yours breaks?
Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.