2019年12月16日 星期一

dir(str) & help(str.replace)




C:\Users\a>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> dir(str)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>>
>>>
模塊下的方法,, 怎麼用? , 使用 help 
>>> help(str.replace)
Help on method_descriptor:

replace(self, old, new, count=-1, /)
    Return a copy with all occurrences of substring old replaced by new.

      count
        Maximum number of occurrences to replace.
        -1 (the default value) means replace all occurrences.

    If the optional argument count is given, only the first count occurrences are
    replaced.


>>>



-------------------------------------------------------------------------------------


Python dir() 函數
描述
dir() 函數不帶參數時,返回當前範圍內的變數、方法和定義的類型列表;帶參數時,返回參數的屬性、方法清單。如果參數包含方法__dir__(),該方法將被調用。如果參數不包含__dir__(),該方法將最大限度地收集參數資訊。
語法
dir 語法:
dir([object])
參數說明:
·         object -- 物件、變數、類型。
返回值
返回模組的屬性清單。
實例
以下實例展示了 dir 的使用方法:
>>>dir() # 獲得當前模組的屬性清單 ['__builtins__', '__doc__', '__name__', '__package__', 'arr', 'myslice'] 
>>> dir([ ​]) # 查看列表的方 ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'
>>>

--------------------------------------------------------------------------------------------------------------------------

Python help() 函數


描述
help() 函數用於查看函數或模組用途的詳細說明。
語法
help 語法:
help([object])
參數說明:
·         object -- 對象;
返回值
返回物件説明資訊。
實例
以下實例展示了 help 的使用方法:
>>>help('sys') # 查看 sys 模組的説明 ……顯示説明資訊…… 
>>>help('str') # 查看 str 資料類型的説明 ……顯示説明資訊…… 
>>>a = [1,2,3] 
>>>help(a) # 查看清單 list 説明資訊 ……顯示説明資訊…… 
>>>help(a.append) # 顯示listappend方法的説明 ……顯示説明資訊……










沒有留言:

張貼留言

print(dir(urllib.request.urlopen(url))) 實作

import urllib.request url = 'http://www.baidu.com/' response = urllib.request.urlopen(url) print(type(response)) print(dir(...