Python代码:
for i in xrange(10):
for j in xrange(5):
pass
# The for-loop ends, but i,j still live on
print i,j # 9, 4
C代码:
for(int i=0; i<=10; i++)
for(int =0; j<=5; j++)
;
// The for-loop ends, so i,j can't be accessed, right?
printf("%d, %d", i, j); // won't compile
那么,Python 中的变量即使在for
循环结束后仍然存在?