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