https://www.cnblogs.com/dflblog/p/11364131.html
兩個函數中調用變量
def test1(): a = 3 return a def test2(): globals()['b'] = 'tarzan' #globals()函數返回字典當前所有的全局變量,並且可以往字典里面添加數據。 print(globals()) def test3(): #想要調用test1中a a = test1() #不要想調用函數。定一個全局變量也可以。但這次試用globle()函數 調用test2中的b值 print(globals()) #他和2中的一樣, 這里有個坑、首先你要先運行test2,才能正常運行test3.自己嘗試一下 name = globals()['b'] print(name) if __name__ == '__main__': test2() test3()