You can either use:

[x / 10.0 for x in range(5, 50, 15)]

or use lambda / map:

map(lambda x: x/10.0, range(5, 50, 15))
Answer from Grzegorz Rożniecki on Stack Overflow
🌐
PYnative
pynative.com › home › python › python range of float numbers
Python range of float numbers
April 13, 2021 - ... Import numpy module using the import numpy as np statement. ... Pass float numbers to its start, stop, and step argument. For example, np.arange(0.5, 6.5, 1.5) will return the sequence of floating-point numbers starting from 0.5 up to 6.5.
Discussions

python - How do I use a decimal step value for range()? - Stack Overflow
I am also quite lazy and so I found ... my own range function. Basically what I did is changed my xrange(0.0, 1.0, 0.01) to xrange(0, 100, 1) and used the division by 100.0 inside the loop. I was also concerned, if there will be rounding mistakes. So I decided to test, whether there are any. Now I heard, that if for example 0.01 from a calculation isn't exactly the float 0.01 comparing ... More on stackoverflow.com
🌐 stackoverflow.com
float numbers with range () function
Yes, range(0, 101) literally gives the integers from 0 to 100. If you want to know if a number is between two values, use a chained comparison: while 0 <= score < 101: Although note you shouldn't get an actual error, just a False. What exact error message did you see? More on reddit.com
🌐 r/learnpython
4
2
April 19, 2022
Float contained in range - Ideas - Discussions on Python.org
I have found that checking if a float number falls inside a range() doesn’t work, always giving False: >>> 1.0 in range (0, 2) True >>> 1.5 in range (0, 2) False I can understand that range() can only accept integer values, but checking if it contains a float number should works. More on discuss.python.org
🌐 discuss.python.org
0
September 7, 2023
python - For loop using range as float object - Stack Overflow
I would like to access multiple pages through this API. Each page has the same URL except for the market_id. I would like to loop through the pages based on the market_id using the specified range.... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-range-for-float-numbers
Python - range() for Float Numbers - GeeksforGeeks
July 23, 2025 - We created a function float_range() that yields values from start to stop with a step size of 0.5. It behaves like a generator and allows us to loop through float numbers.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python range() with float values
Python range() with float values - Spark By {Examples}
May 31, 2024 - Python range() will not be applicable to float values hence, you have to use the NumPy methods to get a list of float values. Using range() with float returns a TypeError. Following are quick examples of how to generate float values using the ...
🌐
Codingem
codingem.com › home › range of floats in python: a step-by-step guide (3 ways to do it)
Range of Floats in Python: A Step-by-Step Guide (3 Ways to Do It)
November 1, 2022 - To create a range of floats in Python, use a list comprehension. For example: [(x/10) for x in range(0, 5)] returns [0.0, 0.1, 0.2, 0.3, 0.4]
🌐
Reddit
reddit.com › r/learnpython › float numbers with range () function
r/learnpython on Reddit: float numbers with range () function
April 19, 2022 -

Hi, I have a section of code which takes a score from the user, typecasts it into a float value and saves it under the variable name "score". Then I have a line of code which reads:

while score not in range(0, 101):

However, when I input a float, I get an invalid input error message from python. I think it's because I can't use the range() function with floats. Is there a way around this? If anyone knows how to solve this, then your help would be greatly appreciated. Thank you in advance.

Find elsewhere
🌐
TechBeamers
techbeamers.com › python-float-range
Generate Floating Point Range in Python - TechBeamers
November 30, 2025 - Python 2 is still getting updates, but newer versions are more stable and advanced. Python range can only generate a set of integer numbers from a given band. Neither does it allow a float type parameter nor it can produce a float range of numbers.
🌐
Guru99
guru99.com › home › python › python range() function: float, list, for loop examples
Python range() Function: Float, List, For loop Examples
August 12, 2024 - Let us now work on the range() using floating-point numbers. ... In above example we have used stop value as 10.5. ... Traceback (most recent call last): File "python_range.py", line 1, in <module> for i in range(10.5): TypeError: 'float' object cannot be interpreted as an integer
🌐
Delft Stack
delftstack.com › home › howto › python › python range float
How to Get Range of Floating Numbers in Python | Delft Stack
February 2, 2024 - The below example code demonstrates how to use the generator comprehension to get the range of floats in Python. seq = (x / 10 for x in range(0, 10)) for x in seq: print(x, end=" ")
🌐
Python.org
discuss.python.org › ideas
Float contained in range - Ideas - Discussions on Python.org
September 7, 2023 - I have found that checking if a float number falls inside a range() doesn’t work, always giving False: >>> 1.0 in range (0, 2) True >>> 1.5 in range (0, 2) False I can understand that range() can only accept integer va…
🌐
YouTube
youtube.com › data science tutorials
Python 3 Programming Tutorial | How to create range values for float data type - YouTube
In this python 3 programming tutorial, I have talked about how you can create range of float values which is directly not possible using the range function. ...
Published   July 4, 2018
Views   1K
🌐
Stack Overflow
stackoverflow.com › questions › 62692063 › for-loop-using-range-as-float-object
python - For loop using range as float object - Stack Overflow
range() only accepts values as int, however you can enter your enter you range as a multiplied by 10 to the power of something, so that the result will be int then for each round of loop divide marketid by the same power of 10.
🌐
GeeksforGeeks
geeksforgeeks.org › python-range-for-float-numbers
Python – range() for Float Numbers | GeeksforGeeks
December 4, 2024 - For example, if the range is from 0 to 10, the resulting list would contain the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8 ... We are given a list of floats and our task is to iterate the list of floats and print the result.
🌐
Toppr
toppr.com › guides › computer-science › introduction-to-python › conditional-constructs-and-looping › for-range-function
For (Range Function): Python range() Basics, Float Numbers, FAQs
May 21, 2021 - Python range() function doesn’t support the float numbers. i.e. we cannot use the floating-point or the non-integer number in any of its arguments.
Top answer
1 of 3
12

You can't use the built in to do float/decimal increments but it is fairly easy to construct your own generator:

def decimal_range(start, stop, increment):
    while start < stop: # and not math.isclose(start, stop): Py>3.5
        yield start
        start += increment

for i in decimal_range(Rangelow, Rangehigh, Delta):
    ...

Or you could use numpy but this feels like a sledgehammer cracking a nut:

import numpy as np
for i in np.arange(Rangelow, Rangehigh, Delta):
    ...
2 of 3
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import decimal

def range_decimal(start, stop, step, stop_inclusive=False):
    """ The Python range() function, using decimals.  A decimal loop_value generator.

    Note: The decimal math (addition) defines the rounding.

    If the stop is None, then:
        stop = start
        start = 0 (zero)

    If the step is 0 (zero) or None, then:
        if (stop < start) then step = -1 (minus one)
        if (stop >= start) then step = 1 (one)

    Example:
        for index in range_decimal(0, 1.0, '.1', stop_inclusive=True):
            print(index)

    :param start: The loop start value
    :param stop: The loop stop value
    :param step: The loop step value
    :param stop_inclusive: Include the stop value in the loop's yield generator: False = excluded ; True = included
    :return: The loop generator's yield increment value (decimal)
    """
    try:
        # Input argument(s) error check
        zero = decimal.Decimal('0')

        if start is None:
            start = zero

        if not isinstance(start, decimal.Decimal):
            start = decimal.Decimal(f'{start}')

        if stop is None:
            stop = start
            start = zero

        if not isinstance(stop, decimal.Decimal):
            stop = decimal.Decimal(f'{stop}')

        if step is None:
            step = decimal.Decimal('-1' if stop < start else '1')

        if not isinstance(step, decimal.Decimal):
            step = decimal.Decimal(f'{step}')

        if step == zero:
            step = decimal.Decimal('-1' if stop < start else '1')

        # Check for valid loop conditions
        if start == stop or (start < stop and step < zero) or (start > stop and step > zero):
            return  # Not valid: no loop

        # Case: increment step ( > 0 )
        if step > zero:
            while start < stop:  # Yield the decimal loop points (stop value excluded)
                yield start
                start += step

        # Case: decrement step ( < 0 )
        else:
            while start > stop:  # Yield the decimal loop points (stop value excluded)
                yield start
                start += step

        # Yield the stop value (inclusive)
        if stop_inclusive:
            yield stop

    except (ValueError, decimal.DecimalException) as ex:
        raise ValueError(f'{__name__}.range_decimal() error: {ex}')

This is a Python range() equivalent function, using decimals. The yielded values are exact.


    Rangelow = 36
    Rangehigh = 37
    Delta = 0.1
    
    print("Celsius to Fahrenheit by", Delta)
    for i in range_decimal(Rangelow, Rangehigh, Delta, stop_inclusive=True):
        print(f'{i:.1f}               {i * 9 / 5 + 32}')

Celsius to Fahrenheit by 0.1
36.0               96.8
36.1               96.98
36.2               97.16
36.3               97.34
36.4               97.52
36.5               97.7
36.6               97.88
36.7               98.06
36.8               98.24
36.9               98.42
37.0               98.6
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 227140 › how-do-i-iterate-through-floating-point-numbers
python - How do I iterate through floating point ... | DaniWeb
October 2, 2009 - r = 6.0 while r < 6.4: print r r += 0.1 """my result --> 6.0 6.1 6.2 6.3 6.4 <--- oops! (float rep of 6.4 --> 6.3999999999999986) """ ... That's fine if you have a nice increment like 0.1, otherwise note that a for loop is just a special case ...
🌐
Python Examples
pythonexamples.org › python-float-range-using-numpy
Python – Float Range using NumPy
You can iterate over this array ... tutorial of Python Ranges, we learned how to create a Range (a numpy array) with Float values using numpy.arange() function, with the help of examples....