【python】疑惑待解决

时间:2022-06-11 20:44:56

1. i 在 for 循环之外,怎么还能输出结果呢?

for i in range(1,10):
        t = 0
    print(i)

2. p为什么没被定义呢?因为没有初始化

import math
import copy
import numpy as np

def main(n):
    global p
    p = np.zero([2,2])
    for i in range(0,n):
        for j in range(0,n):
            p[i,j] = i*j
    for i in range(0,n):
        for j in range(0,n):
            print(p[i,j])
if __name__ == '__main__':    
    main(2)