Use local function variable inside loop [closed]
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . def loop(): d = 0 for x in range(12): d+=1 #this 'd' is not the same as the one above. print(d) In the code above, wouldn't the local variable of the function still be 0? How can I change this to use the function variable instead of the internal variable of the loop? 回答1: I think you've gotten