‘int’ object is not iterable – Python Error

Total
0
Shares

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

Demo might not work in private window (incognito)

Sign Up for Our Newsletters

Get only the best articles delivered to your mail

You May Also Like

modulenotfounderror: no module named ‘numpy’

Table of Contents Hide Installing numpyCheck Environment PATHReinstall Python and NumpyVirtual EnvironmentsRelated Posts: Python throws modulenotfounderror: no module named ‘numpy’, in four conditions – When you have multiple versions of…
View Post
python run bash script in background

python run bash script in background

Table of Contents Hide IntroductionTerminating background script after a timeoutHow to check if process is still running or terminated?How to get output from process?ConclusionLive DemoRelated Posts: Python subprocess library is…
View Post