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()的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab和python哪个运行快_M
- 下一篇: python类实例_类和实例