python光速入门教程_8 自学python内置函数的用法

本文介绍了如何利用help()函数自学Python的基本函数,如print(), eval(), input(),强调了文档在学习过程中的重要性,并提供了在PyCharm中查看函数详情的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值