- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
If you were to use a floating-point number in range() statement , then you would run into "TypeError"
For Example-
for x range in (1.5, 4, 2.5)
y = x + 5
print(y)
Output : TypeError: 'float' object cannot be interpreted as an integer
The range() function does not work with floats. As it takes only integer values as START, STOP And STEP arguments. You can make it work using this method.
for x in range_with_floats (1.5, 4, 2.5)
for x in np.arange (1.5, 4, 2.5)
Comments
Post a Comment