How to fix “typeerror: argument of type ‘builtin_function_or_method’ is not iterable” an error message in Python?
As a developer or programmer, we cannot deny that errors are inevitable, right?
So, if you can’t deal with this “‘argument builtin_function_or_method’ object is not iterable” efficiently, keep reading.
In this article, we are going to delve into the solutions that will help you resolve this error.
But before we dive into the solutions, we should first understand what this error means and why it occurs.
What is “typeerror: argument of type ‘builtin_function_or_method’ is not iterable”?
The “typeerror: argument of type ‘builtin_function_or_method’ is not iterable” occurs when you are trying to iterate over a built-in function or method that is not iterable instead of calling it.
In addition to that, this error happens if you forget to call a method using parentheses () when you are iterating over an object.
When you are using Python, built-in functions must be specified with parenthesis “()” after the name of the function or method.
For example:
my_string = "Hi!"
my_string_lower = my_string.lower
for char in my_string_lower:
print(char)As a result, it will throw an error message. The error was triggered because the lower method was not called with parentheses ().
How to fix “typeerror: argument of type ‘builtin_function_or_method’ is not iterable”?
To fix this error, ensure to call the built-in function or method using parentheses () when you are iterating over an object.
Since, for char in my_string_lower doesn’t have a parentheses (), as we demonstrate above, it will definitely raise an error.
my_string = "Hi!"
my_string_lower = my_string.lower
for char in my_string_lower():
print(char)In this solution, as you can see, we solve the error by putting a parenthesis in my_string_lower().
Output:
h
i
!Here are the following solutions that you can use to fix the error:
1: Call the method using parentheses
When you forget to call a method using parentheses when you are iterating over an object, you’ll get this error.
Ensure to call the method using parentheses.
❌ Incorrect way:
content = inputFile.read().lowerWhen you have a line of code that reads content = inputFile.read().lower, you have change it to content = inputFile.read().lower().
In that way, you are calling the lower method and assigning its return value to the variable content instead of assigning the built-in function lower to your variable content.
✔ Correct way
content = inputFile.read().lower()2: Call the function or method directly instead of iterating over it.
We call the function directly without trying to iterate over it. Since we’re not trying to iterate over the function.
def say_hello():
print("Hello, Welcome to Itsourcecode!")
say_hello()
Output:
Hello, Welcome to Itsourcecode!3: Call the function or method and use the result with the appropriate iterable type
Here, we call the generate_numbers() function and store its output in a list.
Then iterate over the list using a for loop, which works correctly since a list is an iterable data type.
def generate_numbers():
return [10, 20, 30, 40, 50]
numbers = generate_numbers()
for number in numbers:
print(number)
Output:
10
20
30
40
504. Use a different method
When the method you are using is not iterable, try to use a different method that returns an iterable object.
❌ Incorrect way:
my_dict = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5 }
Incorrect
for key in my_dict.keys:
print(key)✔ Correct way
my_dict = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5 }
for key in my_dict.keys():
print(key)Output:
a
b
c
d
e5: Convert the object to an iterable
When the object you are trying to iterate over is not iterable, you can try to convert it to an iterable object, such as a list or a tuple.
my_string = "Hi"
for char in list(my_string):
print(char)Output:
H
iConclusion
In conclusion, the “typeerror: argument of type ‘builtin_function_or_method’ is not iterable” occurs when you are trying to iterate over a built-in function or method that is not iterable instead of calling it.
This error is quite frustrating when you don’t know how to fix it.
Luckily, this article provided several solutions above so that you can fix the “bool’ object is not subscriptable” error message in Python.
We are hoping that this article provided you with sufficient solutions to get rid of the error.
You could also check out other “typeerror” articles that may help you in the future if you encounter them.
- Typeerror: ‘bool’ object is not subscriptable
- Typeerror: ‘bool’ object is not iterable
- Typeerror unsupported operand type s for str and float
Understanding “object is not iterable” TypeErrors
Iteration in Python requires an object that implements the iterator protocol — __iter__ or __getitem__. Integers, None, and single objects do not. This error fires the moment you write “for x in y” or “list(y)” where y is not iterable.
Common triggers
- Iterating over an integer.
for i in 5fails. You wantfor i in range(5). - Iterating over None. Usually from a function that should have returned a list but didn’t.
- Unpacking a scalar.
a, b = some_func()fails if some_func returned a scalar. - Passing a generator that has already been exhausted. Generators yield values only once. Loop over them a second time and you get nothing.
- Confusing dict.keys() with list. dict_keys is iterable but not indexable —
keys[0]fails.
Diagnostic pattern
# BAD
def get_ids():
if not_available:
return None # implicit iterator break
return [1, 2, 3]
for i in get_ids(): # TypeError: 'NoneType' object is not iterable
print(i)
# GOOD — always return an iterable, even when empty
def get_ids():
if not_available:
return []
return [1, 2, 3]
Best practices
- Return an empty list, not None, when a function should yield a sequence.
- Convert once to list if you need to iterate twice:
items = list(generator). - Use isinstance if you accept multiple types:
if isinstance(x, (list, tuple, set)):
Official documentation
Frequently Asked Questions
What is Python TypeError and what causes it?
TypeError is raised when an operation is applied to an object of the wrong type. Common patterns: calling a non-callable object, adding incompatible types (str + int), passing the wrong number of arguments, or accessing attributes on a NoneType. Each TypeError message names the operation and expected vs actual types, the fix is almost always to convert types explicitly (int(), str()) or fix the wrong variable assignment.
How do I quickly debug a Python TypeError?
Three steps: (1) Read the full error message, it names the exact operation and types involved. (2) Print the type of every variable in that line: print(type(var1), type(var2)). (3) Check what the function expected vs what you passed. Most TypeError fixes are 1-line type casts or fixing a variable that became None unexpectedly.
Should I catch TypeError or let it propagate?
For internal code, let TypeError propagate, it’s almost always a real bug (wrong type passed). For boundary code (parsing user input, third-party API responses), catch TypeError + ValueError together: try: parsed = int(value) except (TypeError, ValueError): parsed = 0. Catching internal TypeErrors hides bugs.
How do I prevent TypeError in production?
Three patterns: (1) Use type hints (def add(a: int, b: int) -> int) and check with mypy / pyright in CI. (2) Validate inputs at boundaries (Pydantic for FastAPI, DRF serializers for Django). (3) Default values that match expected types (return 0 not None for numeric functions). Static typing catches 80% of TypeErrors before runtime.
Where can I find more TypeError fixes?
Browse the TypeError reference hub for 220+ specific TypeError fixes. For broader Python debugging, see the Python Tutorial hub. For related error types, see ValueError and AttributeError guides.
