Python | 內置函數(BIF)

来源:https://www.cnblogs.com/tcdhl/archive/2022/05/12/14733614.html
-Advertisement-
Play Games

Python內置函數 | V3.9.1 | 共計155個 還沒學完, 還沒記錄完, 不知道自己能不能堅持記錄下去 1.ArithmeticError 2.AssertionError 3.AttributeError 4.BaseException 5.BlockingIOError 6.Broke ...


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

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
# 機箱 : 海盜船

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

作者:TcDhl —— 大灰狼

出處:http://www.cnblogs.com/tcdhl/

如轉載, 請保留此段申明, 給出原文連接,祝博客園越來越好 !


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 前言 **基礎篇鏈接:**https://www.cnblogs.com/xiegongzi/p/16229678.html 3.9、延遲隊列 - 重要 3.9.1、延遲隊列概念 這個玩意兒要表達的意思其實已經見過了,就是死信隊列中說的TTL消息過期,但是文字表達得換一下 所謂的延遲隊列:就是用來存 ...
  • AQS源碼探究 競爭鎖資源 我們進入ReentrantLock源碼中查看其內部類 Sync 對AQS進行擴展公共方法並定義抽象方法的抽象類 FaireSync 實現公平鎖的AQS的實現類 UnFairSync 實現非公平鎖的ASQ的實現類 我使用例子進行的debug,然後一步一步看源碼。例子在文章最 ...
  • 前言 大麥網是中國綜合類現場娛樂票務營銷平臺,業務覆蓋演唱會、 話劇、音樂劇、體育賽事等領域今天,我們要用代碼來實現他的購票過程 先來看看完成後的效果是怎麼樣的 對於本篇文章有疑問的同學可以加【資料白嫖、解答交流群:753182387】 開發環境 版 本:anaconda(python3.8.8) ...
  • 以前我們定義類都是用class關鍵詞,但從Java 16開始,我們將多一個關鍵詞record,它也可以用來定義類。record關鍵詞的引入,主要是為了提供一種更為簡潔、緊湊的final類的定義方式。 下麵就來具體瞭解record類的細節。配套視頻教程:Java 16 新特性:使用record聲明類 ...
  • Spring Ioc源碼分析系列--Ioc容器BeanFactoryPostProcessor後置處理器分析 前言 上一篇文章Spring Ioc源碼分析系列--Ioc源碼入口分析已經介紹到Ioc容器的入口refresh()方法,並且分析了refresh()方法裡面的前三個子方法分析了一下。還記得分 ...
  • Predicate<T>:常用的四個方法 boolean test(T t):對給定的參數進行判斷(判斷邏輯由Lambda表達式實現),返回一個布爾值 default Predicate<T>negate():返回一個邏輯的否定,對應邏輯非 default Predicate<T>and(Predi ...
  • 停更這些天,業餘時間和粉絲群的幾個大佬合作寫了一個基於Spring Authorization Server的OAuth2授權伺服器的管理控制台項目Id Server,我覺得這個項目能夠大大降低OAuth2授權伺服器使用難度。可以讓你很方便地去管理OAuth2客戶端信息,甚至可以一鍵生成OAuth2 ...
  • 前言 刷題地址:https://buuoj.cn/challenges 首先打開是一個笑臉,查看源代碼,如下圖發現了,一個文件 一.代碼分析 發現是一堆代碼,需要PHP代碼審計,全部代碼如下。 1 <?php 2 highlight_file(lxx_file); 3 class emmm 4 { ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...