Python global variables and local variables
#Python中的变量: Global variables and local variables #在很多语言中, when declaring global variables, like to define the name of the global variable as uppercase #定义学生人数为100STUDENT_NUMBER = 100# School name school_name = ' Guangzhou University ' "" \ Get global variables: Number of students Student_number value "" "Def Getstudentnumber (): Return student_number" "\ Reset Global Change Volume: Student number Student_number value "" "Def Setstudentnumber (num): global student_number student_number = num" "" \ Get Globals: School name Scho Ol_name value "" "Def Getschoolname (): Return school_name" "\ Reset global variable: School name school_name Value" "" Def Setschoolname (name): Global School_name school_name = name def changevalue (): name = ' Peking University ' number = print (' global variable student_number = ', Getstudentnumber ()) print (' global variable school_name = ', Getschoolname ()) print (' ####################################### ') Print (' local variable namber = ', number) print (' local variable name = ', name) print (' ####################################### ') pr Int (' Change global variable Value ... ') print (' ####################################### ') setstudentnumber (number) Setschoolname (name) Print (' global variable student_number = ', gEtstudentnumber ()) print (' global variable school_name = ', Getschoolname ()) If __name__ = = ' __main__ ': ChangeValue ()