Does range() not evaluate its argument every time?

前端 未结 3 867
我寻月下人不归
我寻月下人不归 2021-01-15 11:22

l is passed as an argument to range function whose value is modified inside for loop, but the loop is going for 10 times

3条回答
  •  感动是毒
    2021-01-15 12:05

    The issue is not how often range evaluates its argument, but how often for item in sequence evaluates sequence. The answer is once. When you write for i in range(l), range(l) is evaluated once and that's it.

提交回复
热议问题