... print('This function is named:', amazing.__name__)
... print('And its docstring is:', amazing.__doc__)
...
>>> amazing()
This function is named: amazing
And its docstring is: This is the amazing function.
Want to see it again?
如同先前
globals()
的输出所示,主程序被赋予特殊名称
__main__
。
9.12
递归
到目前为止,我们调用的函数都是直接执行操作,或是再调用其他函数。但如果一个函数
调用自身呢?
9
这叫作
递归
。就像用
while
或
for
弄出来的死循环,你并不想搞个无穷递归
出来。难道还得去操心时空裂缝吗?
Python
再次“出手相救”
:如果调用次数过多,就会产生异常。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.