Python: range function for decimal numbers

前端 未结 4 701
有刺的猬
有刺的猬 2021-01-16 15:22

Is there any range() function in python for float numbers for example

a=0.6

if a in range(0,1):
    a=3

How can i implement this?

4条回答
  •  逝去的感伤
    2021-01-16 15:59

    If you're looking to check whether a is in between two numbers it's better to use:
    0 <=a<=1
    Otherwise , if you do need a list of say 0 to 1 in 0.1 jumps you can use this code to generate it:
    lst = map(lambda x: x/10.0, range(11))

提交回复
热议问题