i 由于在子程序當中,我想設置成全局變量,這樣i可以累加。最后,成功了,代碼如下!
global i
i = 0
def fun1():
global i
for j in "python":
print(j,i)
i=i+1
def fun2():
for j in "123":
fun1()
fun2()
運算結果如圖:
001.jpg
i 由于在子程序當中,我想設置成全局變量,這樣i可以累加。最后,成功了,代碼如下!
global i
i = 0
def fun1():
global i
for j in "python":
print(j,i)
i=i+1
def fun2():
for j in "123":
fun1()
fun2()
運算結果如圖: