yield实现浮点数步长的range

2024-04-23 19:30:53 浏览数 (1)

代码语言:javascript复制
def frange(start,end,step):
    i = start
    while i<end:
        yield i
        i =step

for item in frange(10,14,0.8):
    print(item)

yield会在每次循环进行返回,return只返回一次值

0 人点赞