Python global variables and local variables

Source: Internet
Author: User
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 () 
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.