栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python光速入门教程

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python光速入门教程

使用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

以上就是自学函数使用方法的操作步骤。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1038764.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号