def f(*args):
if len(args)==1:
start,end,step=0,args[0],1
elif len(args)==2:
start,end,step=args[0],args[1],1
elif len(args)==3:
start,end,step=args[0],args[1],args[2]
else:
raise Exception
if step>0:
while start<end:
yield start
start+=step
raise StopIteration
elif step<0:
while start>end:
yield start
start+=step
raise StopIteration
else:
raise("step can't be zero")
自己写个range函数
最新推荐文章于 2024-02-02 09:00:00 发布