Python global variables and local variables

Source: Internet
Author: User
Python global variables and local variables # Python global variables and local variables

# Variables in Python: global variables and local variables # in many languages, when declaring global variables, we all like to define the name of global variables as uppercase # define the number of students as 100STUDENT_NUMBER = 100 # The school name SCHOOL_NAME = 'Guangzhou University '"" \ to get global variables: STUDENT_NUMBER value "" def getStudentNumber (): return STUDENT_NUMBER "" \ reset global variable: STUDENT_NUMBER value "" def setStudentNumber (num ): global STUDENT_NUMBER = num "" \ get global variable: value of the school name SCHOOL_NAME "def getSchoolName (): return SCHOOL_NAME" \ reset global variable: school name SCHOOL_NAME value "def setSchoolName (name): global SCHOOL_NAME = name def changeValue (): name = 'Peking University 'number = 90 print ('Global variable STUDENT_NUMBER = ', getStudentNumber () print ('Global variable SCHOOL_NAME =', getSchoolName ()) print ('##################################### ##') print ('Local variable namber = ', number) print ('Local variable name =', name) print ('##################################### ##') print ('change the global variable value... ') print ('##################################### ##') setStudentNumber (number) setSchoolName (name) print ('Global variable STUDENT_NUMBER = ', getStudentNumber () print ('Global variable SCHOOL_NAME =', getSchoolName ()) if _ name _ = '_ main _': changeValue ()

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.