This article will give you the cause as well as the solution for the “TypeError: ‘float’ object is not iterable” in Python. If you are struggling with this problem, check out the information below for detailed instructions.
The reason why you get this error
When you try to iterate over a floating-point number, you will get the error message: TypeError: ‘float’ object is not iterable” in Python.
Python can only iterate over an iterable object. E.g., lists, strings, tuples, and dictionaries. That’s why an error will occur when you iterate over non-iterable objects. Especially in this post, we are dealing with the error with the float number.
To illustrate, take a look at this example:
floatValue = 8.6 for i in floatValue: print(f'Loop: {i}')
Error:
TypeError: 'float' object is not iterable
This error can also occur when passing a float to a built-in function: list(), tuple(), dict(), or set(). For example:
floatValue = 8.6 list(floatValue)
Error:
TypeError: 'float' object is not iterable
Solved – TypeError: ‘float’ object is not iterable in Python
To solve this problem, you can use the range() statement to iterate over a range of numbers.
Continuing with the error example above, let’s see how we fix it:
floatValue = 8.6 for i in range(int(floatValue)): print(f'Loop: {i}')
Output:
Loop: 0
Loop: 1
Loop: 2
Loop: 3
Loop: 4
Loop: 5
Loop: 6
Loop: 7
As you can see, now the error has been fixed.
We get 8 iterations in the result. The index starts at 0 and ends at 7.
Note: the range() function requires an integer argument, so we also need to use the int() function to convert the float to an integer.
You can try adding more parameters to the range() function to see different results. For example, you want each iteration to be separated by two units, and the starting index is 1:
floatValue = 8.6 for i in range(1, int(floatValue), 2): print(f'Loop: {i}')
Output:
Loop: 1
Loop: 3
Loop: 5
Loop: 7
In case you are working with a built-in function: list(), tuple(), dict(), or set(), do not pass float values as parameters. For instance:
# Pass in a list instead of a float number daysInWeek = list(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) print(daysInWeek)
Output:
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
Summary
To sum up, the error “TypeError: ‘float’ object is not iterable” in Python occurs when you try to iterate over a floating-point number or pass a float to a built-in function: list(), tuple(), dict(), or set(). You can use the range() statement to work around this problem. That’s all we want to convey. Hopefully, this article will help you with your problem.

My name’s Christopher Gonzalez. I graduated from HUST two years ago, and my major is IT. So I’m here to assist you in learning programming languages. If you have any questions about Python, JavaScript, TypeScript, Node.js, React.js, let’s contact me. I will back you up.
Name of the university: HUST
Major: IT
Programming Languages: Python, JavaScript, TypeScript, Node.js, React.js