‘int’ object is not iterable – Python Error


Python throws the error ‘int’ object is not iterable, when we try to use an integer value as an array or list. If you want to make your variable iterable, you need to convert it into string.

Consider this code example –

a = 45678
iterableA = list(a)

This will throw error, int object is not iterable. Although we want to access all the digits in the number separately but this is not a correct way to do that.

The correct code is –

a = 45678
iterableA = list(str(a))

or, we can also do –

a = 45678
iterableA = [a]

    Tweet this to help others

Live Demo

Open Live Demo