def range(*args,**kwargs): if len(args)==1: end=args[0] start=1 step = 1 while start<end: yield start start+=step #pass elif len(args)==2: start=args[0] end=args[1] step=1 while start<end: yield start start+=step #pass elif len(args)==3: start=args[0] end=args[1] step=args[2] while start<end: yield start start+=step #pass else: print("非法输入") print(list(range(2,14,3)))
输出结果:
[2, 5, 8, 11]