Prints the first argument if a second argument is true.
The operation is:
1. Check whether the *second* argument is true.
2. If it is, print the *first* argument.
'''
if check:
print(thing)
要想打印出函数的文档字符串,调用
Python
的
help()
函数即可。传入函数名称,就可以
得到参数列表以及格式整齐的文档字符串:
>>> help(echo)
Help on function echo in module __main__:
echo(anything)
echo returns its input argument
如果你只想查看未经格式化的原始文档字符串,可以运行以下代码:
>>> print(echo.__doc__)
echo returns its input argument
样子古怪的
__doc__
是文档字符串作为函数变量的内部名称。双下划线(在
Python
行话中
又叫作
dunder
8
)在很多地方被用于命名
Python
内部变量,因为程序员不太可能在自己的变
量名中使用双下划线。
9.5
作为
“
头等公民
”
的函数
在
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.