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
# 機箱 : 海盜船
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/
如轉載, 請保留此段申明, 給出原文連接,祝博客園越來越好 !
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/472866.html
標籤:Python
上一篇:【真香定律】再也不用加班了,用Python七大效率工具,輕輕松松就下班
下一篇:Python運算子
