in python for loop the loop variable

Ado, codes serve:

for i in range(3):
    print("hello")

print(i)

Results are as follows:

 

 As can be seen from the above example, for loop inside the loop variable i is derived outside the scope of the cycle. Description loop variable i, the value does not disappear after walking, but retains the value of the last variable, and will overwrite the previous value of the variable! It is usually best not to variables and other variables repeat modules when in use, or it may go wrong!

Guess you like

Origin www.cnblogs.com/xiaohaodeboke/p/12128829.html