python里help和dir的区别_Python中dir()与help()的使用
python内置了很多内置函数、类方法属性及各种模块。当我们想要当我们想要了解某种类型有哪些属性方法以及每种方法该怎么使用时,我们可以使用dir()函数和help()函数在python ide交互式模式下获得我们想要的信息。
dir()
dir()用来查询一个类或者对象所有属性,比如:
>>>dir(list)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']>>>
help()
help()函数帮助我们了解模块、类型、对象、方法、属性的详细信息
1.帮助查看类型详细信息,包含类的创建方式、属性、方法
>>>help(list)
Help onclass list inmodule builtins:classlist(object)| list() ->new empty list| list(iterable) -> new list initialized from iterable's items
|
|Methods defined here:|
| __add__(self, value, /)| Return self+value.|
| __contains__(self, key, /)| Return key inself.|
| __delitem__(self, key, /)|Delete self[key].|
| __eq__(self, value, /)| Return self==value.|
| __ge__(self, value, /)| Return self>=value.|
| __getattribute__(self, name, /)|Return getattr(self, name).|
| __getitem__(...)| x.__getitem__(y) <==>x[y]|
| __gt__(self, value, /)| Return self>value.|
| __iadd__(self, value, /)| Implement self+=value.|
| __imul__(self, value, /)| Implement self*=value.|
| __init__(self, /, *args, **kwargs)-- More --
2.帮助查看方法的详细使用信息(使用时要注意输入完整路径,使用模块帮助时,需要先导入模块)
>>> from selenium.webdriver.common.by importBy>>>help(By)
Help onclass By inmodule selenium.webdriver.common.by:classBy(builtins.object)|Set of supported locator strategies.|
|Data descriptors defined here:|
| __dict__
| dictionary for instance variables (ifdefined)|
| __weakref__
| list of weak references to the object (ifdefined)|
| ----------------------------------------------------------------------
| Data andother attributes defined here:|
| CLASS_NAME = 'class name'
|
| CSS_SELECTOR = 'css selector'
|
| ID = 'id'
|
| LINK_TEXT = 'link text'
|
| NAME = 'name'
|
| PARTIAL_LINK_TEXT = 'partial link text'
|
| TAG_NAME = 'tag name'
|
| 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和dir的区别_Python中dir()与help()的使用相关推荐
- python新式类和经典类区别_Python中新式类和经典类的区别,钻石继承
1)首先,写法不一样: class A: pass class B(object): 2)在多继承中,新式类采用广度优先搜索,而旧式类是采用深度优先搜索. 3)新式类更符合OOP编程思想,统一了pyt ...
- python闭包和装饰器的区别_python中闭包和装饰器的理解(关于python中闭包和装饰器解释最好的文章)。(转)...
呵呵!作为一名教python的老师,我发现学生们基本上一开始很难搞定python的装饰器,也许因为装饰器确实很难懂.搞定装饰器需要你了解一些函数式编程的概念,当然还有理解在python中定义和调用函数 ...
- python中dir的使用_python中dir函数如何使用?
python中,有很多的模块,有的时候搞不清或者记不住这些模块的用法,一个个检索会很麻烦,这时我们可以使用dir函数.dir函数是python中的内置函数,它可以用来列出模块定义的标识符如函数.类和变 ...
- python中dir的使用_python中dir是什么意思
详细内容 python中dir是什么意思? python中dir() 函数不带参数时,返回当前范围内的变量.方法和定义的类型列表:带参数时,返回参数的属性.方法列表.如果参数包含方法__dir__() ...
- python的元组和列表什么区别_Python 中列表和元组有哪些区别?
看过了所有的区别,然而所有的区别都基本毫无意义,tuple元组的设计基本是python语言中一个完全失败和错误的设计,然而我们所有人都只敢小说地说啊它们之间有区别,没有人敢说它们没有区别,是因为这是一 ...
- python find函数 和index的区别_python中index()与find()的区别
起因:在排查错误时定位在判断语句这一行:if testlist.index('T'): 报错:ValueError: substring not found.原来是index()和find()没区分清 ...
- python里eval和input组合使用_python中eval()函数和input()函数用法解析
今天给大家讲解Python中eval()函数和input()函数的用法,希望通过实例的讲解之后大家能对这两个函数有更加深刻的理解. 1.eval()函数 eval()能够以Python表达式的方式解析 ...
- python里面的pip是什么意思_python中的pip是什么意思
pip是Python的包管理器.这意味着它是一个工具,允许你安装和管理不属于标准库的其他库和依赖. 软件包管理极其重要,所以自 Python3 的 3.4 版本以及 Python2 的 2.7.9 版 ...
- python里的map是什么意思_python中的map是什么意思
map()会根据提供的函数对指定序列做映射. 第一个参数function以参数序列中的每一个元素调用function函数,返回包含每次function函数返回值的新列表. map() 函数语法:map ...
最新文章
- 一个类怎样引用另外一个类的成员变量或方法
- python :案例:银行卡
- postgresql 基本语法
- c# XML和实体类之间相互转换(序列化和反序列化)
- 自定义注解 实现自定义消息_实现自定义的未来
- 荟萃分析6项研究表明炎症与骨赘形成有关联
- anaconda下载的python在哪_python包管理器anaconda介绍安装和使用
- 学习笔记之dns正反向解析区域,主从服务,子域授权,安全
- 如果40岁仍碌碌无为,牢记2句话,最迟也是大器晚成
- 20145235 《Java程序设计》第8周学习总结
- a5松下驱动器参数设置表_松下伺服驱动器参数设置MSD043A1X
- qt.qpa.plugin: Could not find the Qt platform plugin “xcb“ in ““ 详细解决办法
- Javaeve博客教你怎么发带图片的博客,非其他网络连接图片
- 4.STM32下载不进程序、程序不运行的可能原因
- 压力测试概念及方法(TPS/并发量)
- c++小游戏:飞机游戏
- 使用charCodeAt()和charAt()方法,根据Unicode 编码,转换字符
- 英特尔® Distribution of OpenVINO™ toolkit 2021 版的发布说明
- 狂神说,mybatis-01 java.lang.ExceptionInInitializerError at com.kuang.dao.UserDaoTest.selectUser(UserD
- 计算机操作系统唤醒原语,计算机操作系统原语分析(范文).doc
热门文章
- 防止网站内容被人小偷和采集的ASP代码
- 十年研发经验嵌入式工程师书籍推荐
- jenkins+gradle/maven+sonar+pipline
- 如何防御潜在的破坏性DDoS攻击—Vecloud微云
- 今天终于把ati集成显卡的linux驱动装好了,看我的3D桌面!哈哈!(博客搬家 2007-07-28 15:56)
- 解决用navicate远程连接数据库出现1045 access denied for user 'root'@'localhost' using password yes...
- python之Django部署
- jQuery 事件绑定
- Android底层开发之Audio HAL Android Audio Overview
- CAS实现单点登录(SSO)经典完整教程