python中不能在外層函數以外調用內層函數


 

1、

內嵌函數的內層函數的作用域在外層函數之內,不能在外層函數外調用內層函數。

>>> def a(): ## 外層函數a(),內層函數b(). print("hello world!") def b(): print("good morning!") return b() >>> a() hello world! good morning!
>>> b() Traceback (most recent call last): File "<pyshell#336>", line 1, in <module> b() NameError: name 'b' is not defined

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM