使用help自学函数用法
print()、eval()、input()、help(),这些是最基本的python函数。当我们遇到不会使用的函数时,先使用help()查看函数的文档,里面有丰富的说明,也配备了详细的demo进行演示,十分方便。这些文档资源是学习的利器。 顺便提一句,软件就是由计算机程序以及文档组成的,文档是十分重要的,一个好的文档对于学习的帮助极大。
下面举例说明如何使用help函数,在pycharm中,输入以下代码。
help(print) # 不能够使用help(print())
就能得到以下结果
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
这里需要注意,python中,函数加上括号表示对函数进行了调用,因此在使用help时,不能够在print函数后面加上括号。
在pycharm中查看函数用法
此外,在pycharm中,我们也能够通过“按住ctrl键并鼠标左击函数名”的方式进入函数内部查看函数是如何实现的。当然,有一些python的函数是通过调用C或C++的程序来实现的,此时进入到函数中是看不到代码的,只有接口说明,这时只需百度该函数了解其用法即可。
例如,在pycharm中ctrl+左击 print函数,可以看到
def print(self, *args, sep=' ', end='\n', file=None): # known special case of print
"""
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
"""
pass
以上就是自学函数使用方法的操作步骤。