1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
def myrange(start, end=None, step=1): if end == None: end = start start = 0 if step > 0: while start < end: yield start start += step elif step < 0: while start > end: yield start start += step else: return 'step can not be zero'
for i in myrange(12, 10, -1): print(i)
|
近期评论