🍉CSDN小墨&晓末:https://blog.csdn.net/jd1813346972
个人介绍: 研一|统计学|干货分享
擅长Python、Matlab、R等主流编程软件
累计十余项国家级比赛奖项,参与研究经费10w、40w级横向
【Python操作基础】系列——帮助文档,建议收藏!
Python的帮助文档通常指的是其官方文档,这些文档包含了Python语言及其标准库、扩展库的详细说明和示例。Python的官方文档非常详细且全面,是学习和使用Python的重要资源。该篇文章主要展示Python编程中帮助文档的使用。
1 help函数
运行程序:
help(len)
运行结果:
Help on built-in function len in module builtins:
len(obj, /)
Return the number of items in a container.
2 DocString
1.
len?
2.
myList1=[1,2,3,4]
myList1.append?
3.
def testDocString():
“”“此处为docString,
即用“?”能查看得到的帮助信息”“”
return(1)testDocString?
PS:?testDocString#?放最前面也可以
3 查看源代码
运行程序:
def testDocString():
"""此处为docString,
即用“?”能查看得到的帮助信息"""
return(1)
testDocString?? #查看源代码--用??
4 doc属性
运行程序:
testDocString.__doc__
运行结果:
'Return the number of items in a container.'
5 dir()函数
运行程序:
dir(print)#查询某个对象所支持的方法
运行结果:
['__call__',
'__class__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__name__',
'__ne__',
'__new__',
'__qualname__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__self__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__text_signature__']
dir? #python采用鸭子类型编程
6 其他方法
myList1.c*? #利用通配符进行自动填充