日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python里help和dir的区别_Python中dir()与help()的使用

發布時間:2025/4/16 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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()的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。