Python3 函數範圍,python3函數

來源:互聯網
上載者:User

Python3 函數範圍,python3函數

 1 # if True: 2 #     x = 3 3 # 4 # print(x) 5 # 6 # def test(): 7 #     a = 10 8 # print(a)    # a未定義 9 10 '''11 Python中的範圍分為四種情況:12 1.L:local,局部範圍,在函數中定義的變數13 2.E:enclosing,嵌套的父級函數的局部範圍,包含此函數的上級函數的局部範圍,但不是全域的14 3.G:global,全域變數,模組層級別定義的變數15 4.B:built-in,系統固定模組裡面的變數,如int,bytearray等。16 17 搜尋變數優先順序:L>E>G>B18 '''19 # 順序例子20 # x = int(5.8)    # 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)    # 未定義30 #     test2()31 # test1()32 33 # count = 1034 # def outer():35 #     print(count)36 # #    count +=1  # 不能修改全域變數,除非建立變數37 # outer()

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.