Python3 function scope, python3 Function

Source: Internet
Author: User

Python3 function scope, python3 Function

1 # if True: 2 # x = 3 3 #4 # print (x) 5 #6 # def test (): 7 # a = 10 8 # print () # a does not define 9 10''' 11 Python has four scopes: 12 1.L: local, local, and the variable 13 2.E: enclosing defined in the function, the local scope of the nested parent-level function, including the local scope of the upper-level function of this function, but not the global 14 3.G: global, global variable, variable 15 4. B: built-in defined at the module level. variables in the system fixed module, such as int and bytearray. 16 17 search for variable priority: L> E> G> B18 ''' 19 # sequence example 20 # x = int (5.8) # The built-in21 # a = 1 # global22 # def test1 (): 23 # B = 2 # enclosing24 #25 # def test2 (): 26 # c = 3 # local27 # print (c) 28 # print (B) 29 # print (c) # undefined 30 # test2 () 31 # test1 () 32 33 # count = 1034 # def outer (): 35 # print (count) 36 # count + = 1 # global variables cannot be modified unless you create variable 37 # outer ()

 

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.