Define global variables python

First: As defined in the class or function in vitro, the need to use global references declared in a class or function 

temp_t = " ceshi " 

DEF   TMP1 (): 

    global temp_t 

    temp_t = 1 Print temp_t 
Results: 1


Second: or a direct function of the class defined in the need to execute the function or class, to perform output 

DEF A ():
     Global CC 
    CC = " BB " 

DEF B ():
     Global CC 
    CC = " KK " 
A () 
B ( ) 
Print (CC) 

results: kk

 

Guess you like

Origin www.cnblogs.com/weilaibuxiangshuo/p/11115973.html