小编给大家分享一下python中使用help()的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

help()函数帮助我们了解模块、类型、对象、方法、属性的详细信息。

1、帮助查看类型详细信息,包含类的创建方式、属性、方法

>>>help(list)Helponclasslistinmodulebuiltins:classlist(object)|list()->newemptylist|list(iterable)->newlistinitializedfromiterable'sitems||Methodsdefinedhere:||__add__(self,value,/)|Returnself+value.||__contains__(self,key,/)|Returnkeyinself.||__delitem__(self,key,/)|Deleteself[key].||__eq__(self,value,/)|Returnself==value.||__ge__(self,value,/)|Returnself>=value.||__getattribute__(self,name,/)|Returngetattr(self,name).||__getitem__(...)|x.__getitem__(y)<==>x[y]||__gt__(self,value,/)|Returnself>value.||__iadd__(self,value,/)|Implementself+=value.||__imul__(self,value,/)|Implementself*=value.||__init__(self,/,*args,**kwargs)--More--

2、帮助查看方法的详细使用信息(使用时要注意输入完整路径,使用模块帮助时,需要先导入模块)

>>>fromselenium.webdriver.common.byimportBy>>>help(By)HelponclassByinmoduleselenium.webdriver.common.by:classBy(builtins.object)|Setofsupportedlocatorstrategies.||Datadescriptorsdefinedhere:||__dict__|dictionaryforinstancevariables(ifdefined)||__weakref__|listofweakreferencestotheobject(ifdefined)||----------------------------------------------------------------------|Dataandotherattributesdefinedhere:||CLASS_NAME='classname'||CSS_SELECTOR='cssselector'||ID='id'||LINK_TEXT='linktext'||NAME='name'||PARTIAL_LINK_TEXT='partiallinktext'||TAG_NAME='tagname'||XPATH='xpath'>>>

3、举例如下:

查看python所有的关键字:help("keywords")

查看python所有的modules:help("modules")

查看python所有的modules中包含指定字符串的modules: help("modules yourstr")

查看python中常见的topics: help("topics")

查看python标准库中的module:import os.path + help("os.path")

查看python内置的类型:help("list")

查看python类型的成员方法:help("str.find")

查看python内置函数:help("open")

以上是python中使用help()的方法的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!