99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2020-08-03 閱讀量: 1044
全局變量可以再什么情況下使用?

當(dāng)局部沒有定義該變量,python會去全局查找該變量,并使用全局查找到的第一個變量,以下代碼展示了這種情況:


# Uses global because there is no local 'a'

def f():

print 'Inside f() : ', a


# Variable 'a' is redefined as a local

def g():

a = 2

print 'Inside g() : ',a


# Uses global keyword to modify global 'a'

def h():

global a

a = 3

print 'Inside h() : ',a


# Global scope

print 'global : ',a

f()

print 'global : ',a

g()

print 'global : ',a

h()

print 'global : ',a



輸出:

global :  1
Inside f() : 1
global : 1
Inside g() : 2
global : 1
Inside h() : 3
global : 3


1.0056
2
關(guān)注作者
收藏
評論(0)

發(fā)表評論

暫無數(shù)據(jù)
推薦帖子