Warning: session_start(): open(/tmp/sess_b34096bb2d13ad1d99525b48ebe1aa63, O_RDWR) failed: Disk quota exceeded (122) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: session_start(): Failed to read session data: files (path: /tmp) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 562

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
How To Fix TypeError: Argument of Type 'int' Is Not Iterable in Python - LearnShareIT

How To Fix TypeError: Argument of Type ‘int’ Is Not Iterable in Python

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.

Leave a Reply

Your email address will not be published. Required fields are marked *