生成浮点数集合

mac2022-06-30  20

""" 实现一个生成浮点数集合的方法 """ def frange(start: float, end: float, inc: float): assert '.' in str(inc) and inc > 0, Exception("增量必须是小数或者大于0") c = len(str(inc)) - 1 - len(str(int(inc))) x = start while x < end: yield round(x, c) x += inc if __name__ == '__main__': l = frange(1, 8, -1.1) print(list(l))

转载于:https://www.cnblogs.com/c-x-a/p/10699099.html

最新回复(0)