Simple question that likely due to keywords, lead to an explanation on the function itself rather than clarification on whether or not the following is the case:
When using the range function to loop, with a function as the stop step, eg
for item in range(some_function()):
#do something
is the result of the function call stored for use or evaluated at each step?
I'd imagine its the former but it agitates that I can't confirm.
There is nothing special about range
here. The behavior is defined in the language reference .
The expression list is evaluated once
The "expression list" is the part after the in
(ie, range(some_function())
in your example). No matter what is there, it is only evaluated once.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.