Python | 內置函數(BIF)

Python內置函數 | V3.9.1 | 共計155個

還沒學完, 還沒記錄完, 不知道自己能不能堅持記錄下去


1.ArithmeticError 2.AssertionError 3.AttributeError 4.BaseException 5.BlockingIOError
6.BrokenPipeError 7.BufferError 8.BytesWarning 9.ChildProcessError 10.ConnectionAbortedError
11.ConnectionError 12.ConnectionRefusedError 13.ConnectionResetError 14.DeprecationWarning 15.EOFError
16.Ellipsis 17.EnvironmentError 18.Exception 19.False 20.FileExistsError
21.FileNotFoundError 22.FloatingPointError 23.FutureWarning 24.GeneratorExit 25.IOError
26.ImportError 27.ImportWarning 28.IndentationError 29.IndexError 30.InterruptedError
31.IsADirectoryError 32.KeyError 33.KeyboardInterrupt 34.LookupError 35.MemoryError
36.ModuleNotFoundError 37.NameError 38.None 39.NotADirectoryError 40.NotImplemented
41.NotImplementedError 42.OSError 43.OverflowError 44.PendingDeprecationWarning 45.PermissionError
46.ProcessLookupError 47.RecursionError 48.ReferenceError 49.ResourceWarning 50.RuntimeError
51.RuntimeWarning 52.StopAsyncIteration 53.StopIteration 54.SyntaxError 55.SyntaxWarning
56.SystemError 57.SystemExit 58.TabError 59.TimeoutError 60.True
61.TypeError 62.UnboundLocalError 63.UnicodeDecodeError 64.UnicodeEncodeError 65.UnicodeError
66.UnicodeTranslateError 67.UnicodeWarning 68.UserWarning 69.ValueError 70.Warning
71.WindowsError 72.ZeroDivisionError 73.__build_class__ 74.__debug__ 75.__doc__
76.__import__ 77.__loader__ 78.__name__ 79.__package__ 80.__spec__
81.abs 82.all 83.any 84.ascii 85.bin
86.bool 87.breakpoint 88.bytearray 89.bytes 90.callable
91.chr 92.classmethod 93.compile 94.complex 95.copyright
96.credits 97.delattr 98.dict 99.dir 100.divmod
101.enumerate 102.eval 103.exec 104.execfile 105.exit
106.filter 107.float 108.format 109.frozenset 110.getattr
111.globals 112.hasattr 113.hash 114help 115.hex
116.id 117.input 118.int 119.isinstance 120.issubclass
121.iter 122.len 123.license 124.list 125.locals
126.map 127.max 128.memoryview 129.min 130.next
131.object 132.oct 133.open 134.ord 135.pow
136.print 137.property 138.quit 139.range 140.repr
141.reversed 142.round 143.runfile 144.set 145.setattr
146.slice 147.sorted 148.staticmethod 149.str 150.sum
151.super 152.tuple 153.type 154.vars 155.zip

1.ArithmeticError

2.AssertionError

3.AttributeError

4.BaseException

5.BlockingIOError

6.BrokenPipeError

7.BufferError

8.BytesWarning

9.ChildProcessError

10.ConnectionAbortedError

11.ConnectionError

12.ConnectionRefusedError

13.ConnectionResetError

14.DeprecationWarning

15.EOFError

16.Ellipsis

17.EnvironmentError

18.Exception

19.False

20.FileExistsError

21.FileNotFoundError

22.FloatingPointError

23.FutureWarning

24.GeneratorExit

25.IOError

26.ImportError

27.ImportWarning

28.IndentationError

29.IndexError

30.InterruptedError

31.IsADirectoryError

32.KeyError

33.KeyboardInterrupt

34.LookupError

35.MemoryError

36.ModuleNotFoundError

37.NameError

38.None

39.NotADirectoryError

40.NotImplemented

41.NotImplementedError

42.OSError

43.OverflowError

44.PendingDeprecationWarning

45.PermissionError

46.ProcessLookupError

47.RecursionError

48.ReferenceError

49.ResourceWarning

50.RuntimeError

51.RuntimeWarning

52.StopAsyncIteration

53.StopIteration

54.SyntaxError

55.SyntaxWarning

56.SystemError

57.SystemExit

58.TabError

59.TimeoutError

60.True

61.TypeError

62.UnboundLocalError

63.UnicodeDecodeError

64.UnicodeEncodeError

65.UnicodeError

66.UnicodeTranslateError

67.UnicodeWarning

68.UserWarning

69.ValueError

70.Warning

71.WindowsError

72.ZeroDivisionError

73.__build_class__

74.__debug__

75.__doc__

76.__import__

77.__loader__

78.__name__

79.__package__

80.__spec__

81.abs

82.all

83.any

84.ascii

85.bin

86.bool

87.breakpoint

88.bytearray

89.bytes

90.callable

91.chr

92.classmethod

修飾符:類方法 @classmethod | 無需顯式地傳遞類名做實參

作為一家“創意+整合+營銷”的成都網站建設機構,我們在業內良好的客戶口碑。創新互聯提供從前期的網站品牌分析策劃、網站設計、網站設計、成都網站制作、創意表現、網頁制作、系統開發以及后續網站營銷運營等一系列服務,幫助企業打造創新的互聯網品牌經營模式與有效的網絡營銷方法,創造更大的價值。

class Computer:
    # 類屬性modules
    __modules = {"cpu":"Intel", "內存":"鎂光", "硬盤":"970-Pro"}

    # 設定修飾符@類方法 | 類的函數或者叫類的方法output_modules
    @classmethod
    def output_modules(cls):
        for (i,s) in cls.__modules.items():
            print(i, ':', s)

# 調用類的方法output_modules,無需顯式地傳遞類名做實參
Computer.output_modules()

#-------------------------------------------------------------
# 輸出結果:
# cpu : Intel
# 內存 : 鎂光
# 硬盤 : 970-Pro

也可被其他類直接進行調用(感覺有點全局的意思), 看例子代碼如下:

class Computer:
    # 類屬性modules
    __modules = {"cpu":"Intel", "內存":"鎂光", "硬盤":"970-Pro"}

    # 設定修飾符@類方法 | 類的函數或者叫類的方法output_modules
    @classmethod
    def output_modules(cls):
        for (i,s) in cls.__modules.items():
            print(i, ':', s)


class OtherClass:
    def __init__(self):
        pass
    def _test_OtherClass(self):
        # 調用類的方法output_modules,無需顯式地傳遞類名做實參
        Computer.output_modules()

aaaa = OtherClass()
aaaa._test_OtherClass()

#-------------------------------------------------------------
# 輸出結果:
# cpu : Intel
# 內存 : 鎂光
# 硬盤 : 970-Pro

93.compile

94.complex

95.copyright

96.credits

97.delattr

98.dict

99.dir

100.divmod

101.enumerate

102.eval

103.exec

104.execfile

105.exit

106.filter

107.float

108.format

109.frozenset

110.getattr

111.globals

112.hasattr

113.hash

114help

115.hex

116.id

117.input

118.int

119.isinstance

120.issubclass

121.iter

122.len

123.license

124.list

125.locals

126.map

127.max

128.memoryview

129.min

130.next

131.object

132.oct

133.open

134.ord

135.pow

136.print

137.property

此修飾符可賦值給變量, 語法為:x = property(getx, setx, delx)

  • 如果是以此種方法的話, 函數名或者說是方法名可以不相同

如果是以裝飾器形式使用的話, 函數名或者說是方法名必須相同, 例子代碼如下:

class Computer:
    # 類屬性 __modules
    __modules = {"cpu":"Intel", "內存":"鎂光", "硬盤":"970-Pro"}
    
    def __init__(self):
        pass

    # 獲取字典的key
    @property
    def modules_property(self):
        # 字典 __modules的key 取出來變成列表
        __loops = [i for i in self.__modules]

        for ii in range(len(self.__modules)):
            print(__loops[ii], ':', self.__modules[__loops[ii]])

    # 給字典新增數據
    @modules_property.setter
    def modules_property(self, key_value):
        self.__modules[key_value[0]] = key_value[1]

    # 刪除字典中內容, 這里沒辦法通過@modules_property.deleter以達到刪除字典中某個鍵值
    # 所以換成了 靜態方法 來刪除鍵值
    @staticmethod
    def del_modules_property(__del, key):
        try:
            # dels.__modules.pop(key, 'Error, 刪除的內容不存在!')
            __del.__modules.pop(key)
        except KeyError:
            print(f'Error, 刪除的鍵: {key} 不存在!')# 這個引用變量 應該在v3.6版本以下不兼容...
            # print('Error, 刪除的鍵: {keys} 不存在!'.format(keys=key))

# 實例化類
aaaa = Computer()

print('打印原有字典內容')
aaaa.modules_property
print('----------分隔符-----------')

print('打印新增后字典內容')
# 通過@modules_property.setter, 給字典新增數據
aaaa.modules_property = ('機箱', '海盜船')
# 通過@property,其實也是@getattr, 取出字典中的鍵值內容
aaaa.modules_property
print('----------分隔符-----------')

print('打印刪除后字典內容')
# 通過靜態方法@staticmethod, 刪除字典中某個元素,或者說成刪除字典中某個鍵值內容
Computer.del_modules_property(Computer, 'cpu')
# 通過@property, 再次打印字典內容,看下是否正常刪除了
aaaa.modules_property

# -------------------------------------------------------------
# 打印原有字典內容
# cpu : Intel
# 內存 : 鎂光
# 硬盤 : 970-Pro
# ----------分隔符-----------
# 打印新增后字典內容
# cpu : Intel
# 內存 : 鎂光
# 硬盤 : 970-Pro
# 機箱 : 海盜船
# ----------分隔符-----------
# 打印刪除后字典內容
# 內存 : 鎂光
# 硬盤 : 970-Pro
# 機箱 : 海盜船

2022-06-01 推翻例子中"刪除字典中內容, 這里沒辦法通過@modules_property.deleter以達到刪除字典中某個鍵值"這句話:

class Computer:
    def __init__(self) -> None:

        self.modules = {"cpu":"intel", "內存":"鎂光", "硬盤":"970-pro"}

        self.moduleslist = []


    @property
    def modulesGetSetDel(self):
        self.moduleslist.clear()
        get_loops = [i for i in self.modules]

        for ii in range(len(self.modules)):

            self.moduleslist.append(get_loops[ii] + ": " + self.modules[get_loops[ii]])
        return self.moduleslist


    @modulesGetSetDel.setter
    def modulesGetSetDel(self, key_value):

        self.get_key_value_loops = [i for i in key_value]
        for i in range(len(self.get_key_value_loops)):
            self.modules[self.get_key_value_loops[i]] =  key_value[self.get_key_value_loops[i]]


    @modulesGetSetDel.deleter
    def modulesGetSetDel(self):
        for i in range(len(self.get_key_value_loops)):
            del self.modules[self.get_key_value_loops[i]]


aa = Computer()

# #打印原始字典
print("原始字典數據: ", aa.modulesGetSetDel)

# #打印新增的字典
aa.modulesGetSetDel = {"機箱":"海盜船", "測試1":"測試11"}
print("新增字典數據: ", aa.modulesGetSetDel)

# 打印刪除后的字典數據
del aa.modulesGetSetDel
print("刪后字典數據: ", aa.modulesGetSetDel)

# -------------------------------------------------------------
# 原始字典數據:  ['cpu: intel', '內存: 鎂光', '硬盤: 970-pro']
# 新增字典數據:  ['cpu: intel', '內存: 鎂光', '硬盤: 970-pro', '機箱: 海盜船', '測試1: 測試11']
# 刪后字典數據:  ['cpu: intel', '內存: 鎂光', '硬盤: 970-pro']

138.quit

139.range

140.repr

141.reversed

142.round

143.runfile

144.set

145.setattr

146.slice

147.sorted

148.staticmethod

# 修飾符:靜態方法 @staticmethod | 必須顯式地傳遞類名做實參

class Computer:
    # 類屬性modules
    __modules = {"cpu":"Intel", "內存":"鎂光", "硬盤":"970-Pro"}

    # 在靜態方法search_module中定義形參var,準備傳遞類:Computer
    # 調用時必須顯性地傳遞類名,才能實現類方法一樣的效果
    # 設定修飾符@靜態方法 | 類的函數或者叫類的方法search_module
    @staticmethod
    def search_module(var, module_value):
        print(var.__modules[module_value])

Computer.search_module(Computer, "cpu")
Computer.search_module(Computer, "內存")
Computer.search_module(Computer, "硬盤")

#-------------------------------------------------------------
# 輸出結果:
# Intel
# 鎂光
# 970-Pro

也可被其他類直接進行調用(有點全局的意思.....), 看例子代碼如下:

class Computer:
    # 類屬性modules
    __modules = {"cpu":"Intel", "內存":"鎂光", "硬盤":"970-Pro"}

    # 在靜態方法search_module中定義形參var,準備傳遞類:Computer
    # 調用時必須顯性地傳遞類名,才能實現類方法一樣的效果
    # 設定修飾符@靜態方法 | 類的函數或者叫類的方法search_module
    @staticmethod
    def search_module(var, module_value):
        print(var.__modules[module_value])


class OtherClass:
    def __init__(self):
        pass

    def _test_OtherClass(self):
        # 調用類的靜態方法search_module,必須顯式地傳遞類名做實參
        Computer.search_module(Computer, "cpu")
        Computer.search_module(Computer, "內存")
        Computer.search_module(Computer, "硬盤")

aaaa = OtherClass()
aaaa._test_OtherClass()

#-------------------------------------------------------------
# 輸出結果:
# Intel
# 鎂光
# 970-Pro

149.str

150.sum

151.super

super函數不需要明確的給出任何 "被調用類" 的名稱, 學習中覺得 子類-父類-超類 叫起來很繞, 就自認為叫成 "被調用類" 方便自己理解

  • 假設定義了三個類: A B C
  • 類A 繼承 類B, 類A 是 類B 的子類 | 類B 是 類A 的父類(被調用類)
  • 類B 繼承 類C, 類B 是 類C 的子類 | 類C 是 類B 的父類(被調用類)
  • 類A 間接繼承 類C , 類C 是 類A 的超類(被調用類)
  • 例子待定

152.tuple

153.type

154.vars

155.zip

當前文章:Python | 內置函數(BIF)
網站路徑:http://m.kartarina.com/article10/dsogpdo.html

成都網站建設公司_創新互聯,為您提供網站制作定制開發面包屑導航品牌網站建設虛擬主機網站改版

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都app開發公司
主站蜘蛛池模板: 少妇无码一区二区三区免费| 久久久久无码国产精品不卡| 国产V亚洲V天堂无码| 成年男人裸j照无遮挡无码| 亚洲AV无码一区二区三区电影| 无码人妻丰满熟妇啪啪| 特级无码毛片免费视频尤物| 精品人妻无码专区在中文字幕 | 亚洲一级特黄无码片| 亚洲成AV人在线播放无码| 曰韩无码二三区中文字幕| 亚洲A∨无码无在线观看| 国产av无码专区亚洲av毛片搜| 人妻丝袜中文无码av影音先锋专区| 无码av大香线蕉伊人久久| 中文字幕人成无码免费视频| 东京热人妻无码人av| 少妇无码太爽了不卡视频在线看| AV大片在线无码永久免费| 亚洲av无码乱码国产精品| 亚洲AV无码一区二区三区国产| 亚洲av无码专区在线电影天堂| 无码国产精成人午夜视频一区二区 | 精品久久无码中文字幕| 亚洲啪啪AV无码片| 国产精品无码不卡一区二区三区| 无码任你躁久久久久久| 亚洲国产精品无码久久久秋霞1| 无码欧精品亚洲日韩一区| 国产精品免费无遮挡无码永久视频 | 久久青草亚洲AV无码麻豆| 日韩精品无码视频一区二区蜜桃| 国产午夜鲁丝片AV无码免费| 无码人妻精品丰满熟妇区| 无码里番纯肉h在线网站| 国产精品无码久久综合网| 亚洲AV无码国产剧情| 免费无码不卡视频在线观看| 国产AV无码专区亚洲AV麻豆丫| 久久久久久亚洲精品无码| 国产成人无码A区精油按摩|