Change step value inside range function?

前端 未结 5 1158
醉话见心
醉话见心 2020-12-21 19:58
list1 = [1, 2, 3, 4]

i\'m trying to figure out a way to change the step value for each printed i

What I\'ve tried

r = 0
for         


        
5条回答
  •  北海茫月
    2020-12-21 20:22

    This is not supported by the range function. You have to do the iteration explicitly.

    for elem in list1:
      i += elem
      if i > 10:
        break
      print i
    

提交回复
热议问题