In python, the variables defined by the module can be considered as global variables, but you need to pay attention to the assignment of global variables.
Test. PY ---------------------------------------------- import sysusername = "muzizongheng" Password = "XXXX" def login (u, p): username = u Password = P print ("username:", username) print ("Password:", password) ------------------------------------------------- the global variables username and password in the above Code are not changed. The variables assigned by the default function or method in Python do not need to be made public, local variables are used by default. To change the global variable, change it to Def login (u, p): Global username global password username = u Password = P print ("username:", username) print ("password: ", password)
That is, global variables should be declared using the Global keyword.