Python3 笔记:help()查看函数的用法

一些不常用的函数或是模块的用法记不清了怎么办?

Python的内置函数help()可以查看函数或模块用途的详细说明。

操作方法很简单,直接在help()括号内填写参数,然后运行就可以看到结果了。

举例:

help(input)	# 查询input()函数的用法
"""
运行结果:
Help on built-in function input in module builtins:

input(prompt=None, /)
    Read a string from standard input.  The trailing newline is stripped.
    
    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.
    
    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.
"""

help(len)	# 查询len()函数的用法
"""
运行结果:
Help on built-in function len in module builtins:

len(obj, /)
    Return the number of items in a container.
"""

同样可以查询自定义函数的用法。举例:

# 定义一个informa()函数,包含Name,Age,ID三个参数
def informa(Name,Age,ID):
	print('Name: ',Name)
	print('Age: ',Age)
	print('ID: ',ID)
# 调用已经定义好的informa()函数
Name = 'Mark'
Age = 30
ID = 12345678
informa(Name,Age,ID)
"""
运行结果:
Name:  Mark
Age:  30
ID:  12345678
"""
help(informa)	# 查询自定义函数informa()的用法
"""
运行结果:
Help on function informa in module __main__:

informa(Name, Age, ID)
    # 定义一个informa()函数,包含Name,Age,ID三个参数
"""

Python3 笔记:Python3 在线工具、Python在线编程-CSDN博客

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值