Python 踩坑之嵌套函數,python踩坑嵌套

來源:互聯網
上載者:User

Python 踩坑之嵌套函數,python踩坑嵌套

這裡需要特別注意一下, Python是解釋類型的語言. 會允許在定義A函數之前沒有定義B函數的情況下,函數A調用函數B.

def func1():    print "Hello fun1"    fun2()def func2():    print "Hello func2"fun1()

這樣做是可以的.但是試想一下, 如果函數2也調用函數1呢?

如下:

def func1():    print "Hello fun1"    fun2()def func2():    print "Hello func2"    fun1()fun1()

這就是個嵌套調用.會爆棧的...
因為不是編譯性語言,這種問題很難預先用文法分析出來,很可能python為了追求速度,不去分析這種錯誤.
因此寫程式的時候要特別注意, 不要兩個或者多個函數之間嵌套調用...
當然,我沒有這麼幹,只是嘗試了一下,原來python還真可以嵌套定義函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.