While developing your Python program, you may get an error message: TypeError: argument of type 'int' is not iterable
in Python. There should be no worry as this TypeError is common. This article will explain the cause and give the solutions.
Cause of TypeError: argument of type ‘int’ is not iterable in Python
The TypeError: argument of type 'int' is not iterable
in Python occurs when you try to iterate through an int
. Below is a code sample that leads to the problem:
iNumber = 5 iObject = 10 # iterate iNumber through int iObject print(iNumber in iObject)
The error message will show up:
print(iNumber in iObject)
TypeError: argument of type 'int' is not iterable
Remember that you can only iterate an object that is iterable. This means you can only search for a value in a []
list, a ()
tuple, or a {}
dictionary, as these are iterable. There is no way you can search for a value in a non-iterable object, such as an int
.
How to fix TypeError: argument of type ‘int’ is not iterable in Python
As mentioned, if you iterate a non-iterable object such as an int
, you will get the message: TypeError: argument of type 'int' is not iterable
in Python. Otherwise, if iterating an iterable object, you will receive a return value of True
or False
.
Below are several solutions to fix the TypeError above:
Putting the int in an iterable object
You only have permission to iterable an iterable object. Therefore, add the int object in a list []
, tuple ()
, or dict {}
and the code will work!
Here is the code sample:
iNumber = 5 lstObject = [10] # iterate iNumber through the list lstObject print(iNumber in lstObject)
As there is no value 5 in the list iObject, the output will be:
False
If there is a value 5 in the list iObject, the output can be a True when you iterate the iNumber = 5 through the iObject.
Here is the code sample:
iNumber = 5 lstObject = [10, 5] # iterate iNumber through the list lstObject print(iNumber in lstObject)
This time, the output will be:
True
Using list(), tuple(), or dict() function
It is also good to put the object in a list()
, tuple()
, or dict()
function. These 3 functions create an iterable that stores the object as its value. You can easily search for this object without receiving the error message.
Here is the code sample:
iNumber = 5 lstObject = list() lstObject.append(5) # iterate iNumber through the list lstObject print(iNumber in lstObject)
The output will be:
True
Using ==
There is a way to not use non-iterable objects. Since you have 2 separate integers to compare, you have to use the ==
operator instead of the “in”. The output will still be either True
or False
.
Here is the code sample:
iNumber = 5 iObject = [10] # compare iNumber == int iObject print(iNumber == iObject)
The output will be:
False
Summary
The error message TypeError: argument of type 'int' is not iterable
in Python occurs when you try to iterable an int
object. The solution for this issue is to put the int
object in an iterable. On the other hand, if you have to use the ==
operator to compare an int
to an int
.

I am William Nguyen and currently work as a software developer. I am highly interested in programming, especially in Python, C++, Html, Css, and Javascript. I’ve worked on numerous software development projects throughout the years. I am eager to share my knowledge with others that enjoy programming!