Python內建函數詳解——總結篇

來源:互聯網
上載者:User

標籤:全域   可迭代對象   code   student   str   abc   返回   __str__   dexp   

  •     數學運算(7個)
  •     類型轉換(24個)
  •     序列操作(8個)
  •     對象操作(7個)
  •     反射操作(8個)
  •     變數操作(2個)
  •     互動操作(2個)
  •     檔案操作(1個)
  •     編譯執行(4個)
  •     裝飾器(3個)
 數學運算 abs:求數值的絕對值>>> abs(-2)2divmod:返回兩個數值的商和餘數>>> divmod(5,2)(2, 1)>> divmod(5.5,2)(2.0, 1.5)max:返回可迭代對象中的元素中的最大值或者所有參數的最大值複製代碼>>> max(1,2,3) # 傳入3個參數 取3個中較大者3>>> max(‘1234‘) # 傳入1個可迭代對象,取其最大元素值‘4‘>>> max(-1,0) # 數值預設去數值較大者0>>> max(-1,0,key = abs) # 傳入了求絕對值函數,則參數都會進行求絕對值後再取較大者-1複製代碼min:返回可迭代對象中的元素中的最小值或者所有參數的最小值複製代碼>>> min(1,2,3) # 傳入3個參數 取3個中較小者1>>> min(‘1234‘) # 傳入1個可迭代對象,取其最小元素值‘1‘>>> min(-1,-2) # 數值預設去數值較小者-2>>> min(-1,-2,key = abs)  # 傳入了求絕對值函數,則參數都會進行求絕對值後再取較小者-1複製代碼pow:返回兩個數值的冪運算值或其與指定整數的模值>>> pow(2,3)>>> 2**3>>> pow(2,3,5)>>> pow(2,3)%5round:對浮點數進行四捨五入求值>>> round(1.1314926,1)1.1>>> round(1.1314926,5)1.13149sum:對元素類型是數值的可迭代對象中的每個元素求和複製代碼# 傳入可迭代對象>>> sum((1,2,3,4))10# 元素類型必須是數值型>>> sum((1.5,2.5,3.5,4.5))12.0>>> sum((1,2,3,4),-10)0複製代碼     類型轉換 bool:根據傳入的參數的邏輯值建立一個新的布爾值>>> bool() #未傳入參數False>>> bool(0) #數值0、空序列等值為FalseFalse>>> bool(1)Trueint:根據傳入的參數建立一個新的整數>>> int() #不傳入參數時,得到結果0。0>>> int(3)3>>> int(3.6)3float:根據傳入的參數建立一個新的浮點數>>> float() #不提供參數的時候,返回0.00.0>>> float(3)3.0>>> float(‘3‘)3.0complex:根據傳入參數建立一個新的複數>>> complex() #當兩個參數都不提供時,返回複數 0j。0j>>> complex(‘1+2j‘) #傳入字串建立複數(1+2j)>>> complex(1,2) #傳入數值建立複數(1+2j)str:返回一個對象的字串表現形式(給使用者)複製代碼>>> str()‘‘>>> str(None)‘None‘>>> str(‘abc‘)‘abc‘>>> str(123)‘123‘複製代碼bytearray:根據傳入的參數建立一個新的位元組數組>>> bytearray(‘中文‘,‘utf-8‘)bytearray(b‘\xe4\xb8\xad\xe6\x96\x87‘)bytes:根據傳入的參數建立一個新的不可變位元組數組>>> bytes(‘中文‘,‘utf-8‘)b‘\xe4\xb8\xad\xe6\x96\x87‘memoryview:根據傳入的參數建立一個新的記憶體查看對象>>> v = memoryview(b‘abcefg‘)>>> v[1]98>>> v[-1]103ord:返回Unicode字元對應的整數>>> ord(‘a‘)97chr:返回整數所對應的Unicode字元>>> chr(97) #參數類型為整數‘a‘bin:將整數轉換成2進位字串>>> bin(3) ‘0b11‘oct:將整數轉化成8進位數字串>>> oct(10)‘0o12‘hex:將整數轉換成16進位字串>>> hex(15)‘0xf‘tuple:根據傳入的參數建立一個新的元組>>> tuple() #不傳入參數,建立空元組()>>> tuple(‘121‘) #傳入可迭代對象。使用其元素建立新的元組(‘1‘, ‘2‘, ‘1‘)list:根據傳入的參數建立一個新的列表>>>list() # 不傳入參數,建立空列表[] >>> list(‘abcd‘) # 傳入可迭代對象,使用其元素建立新的列表[‘a‘, ‘b‘, ‘c‘, ‘d‘]dict:根據傳入的參數建立一個新的字典複製代碼>>> dict() # 不傳入任何參數時,返回空字典。{}>>> dict(a = 1,b = 2) #  可以傳入索引值對建立字典。{‘b‘: 2, ‘a‘: 1}>>> dict(zip([‘a‘,‘b‘],[1,2])) # 可以傳入映射函數建立字典。{‘b‘: 2, ‘a‘: 1}>>> dict(((‘a‘,1),(‘b‘,2))) # 可以傳入可迭代對象建立字典。{‘b‘: 2, ‘a‘: 1}複製代碼set:根據傳入的參數建立一個新的集合>>>set() # 不傳入參數,建立空集合set()>>> a = set(range(10)) # 傳入可迭代對象,建立集合>>> a{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}frozenset:根據傳入的參數建立一個新的不可變集合>>> a = frozenset(range(10))>>> afrozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})enumerate:根據可迭代對象建立枚舉對象>>> seasons = [‘Spring‘, ‘Summer‘, ‘Fall‘, ‘Winter‘]>>> list(enumerate(seasons))[(0, ‘Spring‘), (1, ‘Summer‘), (2, ‘Fall‘), (3, ‘Winter‘)]>>> list(enumerate(seasons, start=1)) #指定起始值[(1, ‘Spring‘), (2, ‘Summer‘), (3, ‘Fall‘), (4, ‘Winter‘)]range:根據傳入的參數建立一個新的range對象複製代碼>>> a = range(10)>>> b = range(1,10)>>> c = range(1,10,3)>>> a,b,c # 分別輸出a,b,c(range(0, 10), range(1, 10), range(1, 10, 3))>>> list(a),list(b),list(c) # 分別輸出a,b,c的元素([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 4, 7])>>>複製代碼iter:根據傳入的參數建立一個新的可迭代對象複製代碼>>> a = iter(‘abcd‘) #字串序列>>> a<str_iterator object at 0x03FB4FB0>>>> next(a)‘a‘>>> next(a)‘b‘>>> next(a)‘c‘>>> next(a)‘d‘>>> next(a)Traceback (most recent call last):  File "<pyshell#29>", line 1, in <module>    next(a)StopIteration複製代碼slice:根據傳入的參數建立一個新的切片對象複製代碼>>> c1 = slice(5) # 定義c1>>> c1slice(None, 5, None)>>> c2 = slice(2,5) # 定義c2>>> c2slice(2, 5, None)>>> c3 = slice(1,10,3) # 定義c3>>> c3slice(1, 10, 3)複製代碼super:根據傳入的參數建立一個新的子類和父類別關係的代理對象複製代碼#定義父類A>>> class A(object):    def __init__(self):        print(‘A.__init__‘)#定義子類B,繼承A>>> class B(A):    def __init__(self):        print(‘B.__init__‘)        super().__init__()#super調用父類方法>>> b = B()B.__init__A.__init__複製代碼object:建立一個新的object對象>>> a = object()>>> a.name = ‘kim‘ # 不能設定屬性Traceback (most recent call last):  File "<pyshell#9>", line 1, in <module>    a.name = ‘kim‘AttributeError: ‘object‘ object has no attribute ‘name‘    序列操作 all:判斷可迭代對象的每個元素是否都為True值複製代碼>>> all([1,2]) #列表中每個元素邏輯值均為True,返回TrueTrue>>> all([0,1,2]) #列表中0的邏輯值為False,返回FalseFalse>>> all(()) #空元組True>>> all({}) #空字典True複製代碼any:判斷可迭代對象的元素是否有為True值的元素複製代碼>>> any([0,1,2]) #列表元素有一個為True,則返回TrueTrue>>> any([0,0]) #列表元素全部為False,則返回FalseFalse>>> any([]) #空列表False>>> any({}) #空字典False複製代碼filter:使用指定方法過濾可迭代對象的元素複製代碼>>> a = list(range(1,10)) #定義序列>>> a[1, 2, 3, 4, 5, 6, 7, 8, 9]>>> def if_odd(x): #定義奇數判斷函數    return x%2==1>>> list(filter(if_odd,a)) #篩選序列中的奇數[1, 3, 5, 7, 9]複製代碼map:使用指定方法去作用傳入的每個可迭代對象的元素,產生新的可迭代對象>>> a = map(ord,‘abcd‘)>>> a<map object at 0x03994E50>>>> list(a)[97, 98, 99, 100]next:返回可迭代對象中的下一個元素值複製代碼>>> a = iter(‘abcd‘)>>> next(a)‘a‘>>> next(a)‘b‘>>> next(a)‘c‘>>> next(a)‘d‘>>> next(a)Traceback (most recent call last):  File "<pyshell#18>", line 1, in <module>    next(a)StopIteration#傳入default參數後,如果可迭代對象還有元素沒有返回,則依次返回其元素值,如果所有元素已經返回,則返回default指定的預設值而不拋出StopIteration 異常>>> next(a,‘e‘)‘e‘>>> next(a,‘e‘)‘e‘複製代碼reversed:反轉序列產生新的可迭代對象>>> a = reversed(range(10)) # 傳入range對象>>> a # 類型變成迭代器<range_iterator object at 0x035634E8>>>> list(a)[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]sorted:對可迭代對象進行排序,返回一個新的列表複製代碼>>> a = [‘a‘,‘b‘,‘d‘,‘c‘,‘B‘,‘A‘]>>> a[‘a‘, ‘b‘, ‘d‘, ‘c‘, ‘B‘, ‘A‘]>>> sorted(a) # 預設按字元ascii碼排序[‘A‘, ‘B‘, ‘a‘, ‘b‘, ‘c‘, ‘d‘]>>> sorted(a,key = str.lower) # 轉換成小寫後再排序,‘a‘和‘A‘值一樣,‘b‘和‘B‘值一樣[‘a‘, ‘A‘, ‘b‘, ‘B‘, ‘c‘, ‘d‘]複製代碼zip:彙總傳入的每個迭代器中相同位置的元素,返回一個新的元群組類型迭代器>>> x = [1,2,3] #長度3>>> y = [4,5,6,7,8] #長度5>>> list(zip(x,y)) # 取最小長度3[(1, 4), (2, 5), (3, 6)]   對象操作 help:返回對象的協助資訊複製代碼>>> help(str) Help on class str in module builtins:class str(object) |  str(object=‘‘) -> str |  str(bytes_or_buffer[, encoding[, errors]]) -> str |   |  Create a new string object from the given object. If encoding or |  errors is specified, then the object must expose a data buffer |  that will be decoded using the given encoding and error handler. |  Otherwise, returns the result of object.__str__() (if defined) |  or repr(object). |  encoding defaults to sys.getdefaultencoding(). |  errors defaults to ‘strict‘. |   |  Methods defined here: |   |  __add__(self, value, /) |      Return self+value. |    ***************************複製代碼dir:返回對象或者當前範圍內的屬性列表複製代碼>>> import math>>> math<module ‘math‘ (built-in)>>>> dir(math)[‘__doc__‘, ‘__loader__‘, ‘__name__‘, ‘__package__‘, ‘__spec__‘, ‘acos‘, ‘acosh‘, ‘asin‘, ‘asinh‘, ‘atan‘, ‘atan2‘, ‘atanh‘, ‘ceil‘, ‘copysign‘, ‘cos‘, ‘cosh‘, ‘degrees‘, ‘e‘, ‘erf‘, ‘erfc‘, ‘exp‘, ‘expm1‘, ‘fabs‘, ‘factorial‘, ‘floor‘, ‘fmod‘, ‘frexp‘, ‘fsum‘, ‘gamma‘, ‘gcd‘, ‘hypot‘, ‘inf‘, ‘isclose‘, ‘isfinite‘, ‘isinf‘, ‘isnan‘, ‘ldexp‘, ‘lgamma‘, ‘log‘, ‘log10‘, ‘log1p‘, ‘log2‘, ‘modf‘, ‘nan‘, ‘pi‘, ‘pow‘, ‘radians‘, ‘sin‘, ‘sinh‘, ‘sqrt‘, ‘tan‘, ‘tanh‘, ‘trunc‘]複製代碼id:返回對象的唯一識別碼>>> a = ‘some text‘>>> id(a)69228568hash:擷取對象的雜湊值>>> hash(‘good good study‘)1032709256type:返回對象的類型,或者根據傳入的參數建立一個新的類型複製代碼>>> type(1) # 返回對象的類型<class ‘int‘>#使用type函數建立類型D,含有屬性InfoD>>> D = type(‘D‘,(A,B),dict(InfoD=‘some thing defined in D‘))>>> d = D()>>> d.InfoD ‘some thing defined in D‘複製代碼len:返回對象的長度複製代碼>>> len(‘abcd‘) # 字串>>> len(bytes(‘abcd‘,‘utf-8‘)) # 位元組數組>>> len((1,2,3,4)) # 元組>>> len([1,2,3,4]) # 列表>>> len(range(1,5)) # range對象>>> len({‘a‘:1,‘b‘:2,‘c‘:3,‘d‘:4}) # 字典>>> len({‘a‘,‘b‘,‘c‘,‘d‘}) # 集合>>> len(frozenset(‘abcd‘)) #不可變集合複製代碼ascii:返回對象的可列印表字串表現方式複製代碼>>> ascii(1)‘1‘>>> ascii(‘&‘)"‘&‘">>> ascii(9000000)‘9000000‘>>> ascii(‘中文‘) #非ascii字元"‘\\u4e2d\\u6587‘"複製代碼format:格式化顯示值複製代碼#字串可以提供的參數 ‘s‘ None>>> format(‘some string‘,‘s‘)‘some string‘>>> format(‘some string‘)‘some string‘#整形數值可以提供的參數有 ‘b‘ ‘c‘ ‘d‘ ‘o‘ ‘x‘ ‘X‘ ‘n‘ None>>> format(3,‘b‘) #轉換成二進位‘11‘>>> format(97,‘c‘) #轉換unicode成字元‘a‘>>> format(11,‘d‘) #轉換成10進位‘11‘>>> format(11,‘o‘) #轉換成8進位‘13‘>>> format(11,‘x‘) #轉換成16進位 小寫字母表示‘b‘>>> format(11,‘X‘) #轉換成16進位 大寫字母表示‘B‘>>> format(11,‘n‘) #和d一樣‘11‘>>> format(11) #預設和d一樣‘11‘#浮點數可以提供的參數有 ‘e‘ ‘E‘ ‘f‘ ‘F‘ ‘g‘ ‘G‘ ‘n‘ ‘%‘ None>>> format(314159267,‘e‘) #科學計數法,預設保留6位小數‘3.141593e+08‘>>> format(314159267,‘0.2e‘) #科學計數法,指定保留2位小數‘3.14e+08‘>>> format(314159267,‘0.2E‘) #科學計數法,指定保留2位小數,採用大寫E表示‘3.14E+08‘>>> format(314159267,‘f‘) #小數點計數法,預設保留6位小數‘314159267.000000‘>>> format(3.14159267000,‘f‘) #小數點計數法,預設保留6位小數‘3.141593‘>>> format(3.14159267000,‘0.8f‘) #小數點計數法,指定保留8位小數‘3.14159267‘>>> format(3.14159267000,‘0.10f‘) #小數點計數法,指定保留10位小數‘3.1415926700‘>>> format(3.14e+1000000,‘F‘)  #小數點計數法,無窮大轉換成大小字母‘INF‘#g的格式化比較特殊,假設p為格式中指定的保留小數位元,先嘗試採用科學計數法格式化,得到冪指數exp,如果-4<=exp<p,則採用小數計數法,並保留p-1-exp位小數,否則按小數計數法計數,並按p-1保留小數位元>>> format(0.00003141566,‘.1g‘) #p=1,exp=-5 ==》 -4<=exp<p不成立,按科學計數法計數,保留0位小數點‘3e-05‘>>> format(0.00003141566,‘.2g‘) #p=1,exp=-5 ==》 -4<=exp<p不成立,按科學計數法計數,保留1位小數點‘3.1e-05‘>>> format(0.00003141566,‘.3g‘) #p=1,exp=-5 ==》 -4<=exp<p不成立,按科學計數法計數,保留2位小數點‘3.14e-05‘>>> format(0.00003141566,‘.3G‘) #p=1,exp=-5 ==》 -4<=exp<p不成立,按科學計數法計數,保留0位小數點,E使用大寫‘3.14E-05‘>>> format(3.1415926777,‘.1g‘) #p=1,exp=0 ==》 -4<=exp<p成立,按小數計數法計數,保留0位小數點‘3‘>>> format(3.1415926777,‘.2g‘) #p=1,exp=0 ==》 -4<=exp<p成立,按小數計數法計數,保留1位小數點‘3.1‘>>> format(3.1415926777,‘.3g‘) #p=1,exp=0 ==》 -4<=exp<p成立,按小數計數法計數,保留2位小數點‘3.14‘>>> format(0.00003141566,‘.1n‘) #和g相同‘3e-05‘>>> format(0.00003141566,‘.3n‘) #和g相同‘3.14e-05‘>>> format(0.00003141566) #和g相同‘3.141566e-05‘複製代碼vars:返回當前範圍內的局部變數和其值組成的字典,或者返回對象的屬性列表複製代碼#作用於類執行個體>>> class A(object):    pass>>> a.__dict__{}>>> vars(a){}>>> a.name = ‘Kim‘>>> a.__dict__{‘name‘: ‘Kim‘}>>> vars(a){‘name‘: ‘Kim‘}複製代碼   反射操作 __import__:動態匯入模組index = __import__(‘index‘)index.sayHello()isinstance:判斷對象是否是類或者類型元組中任意類元素的執行個體>>> isinstance(1,int)True>>> isinstance(1,str)False>>> isinstance(1,(int,str))Trueissubclass:判斷類是否是另外一個類或者類型元組中任意類元素的子類複製代碼>>> issubclass(bool,int)True>>> issubclass(bool,str)False>>> issubclass(bool,(str,int))True複製代碼hasattr:檢查對象是否含有屬性複製代碼#定義類A>>> class Student:    def __init__(self,name):        self.name = name        >>> s = Student(‘Aim‘)>>> hasattr(s,‘name‘) #a含有name屬性True>>> hasattr(s,‘age‘) #a不含有age屬性False複製代碼getattr:擷取對象的屬性值複製代碼#定義類Student>>> class Student:    def __init__(self,name):        self.name = name>>> getattr(s,‘name‘) #存在屬性name‘Aim‘>>> getattr(s,‘age‘,6) #不存在屬性age,但提供了預設值,返回預設值>>> getattr(s,‘age‘) #不存在屬性age,未提供預設值,調用報錯Traceback (most recent call last):  File "<pyshell#17>", line 1, in <module>    getattr(s,‘age‘)AttributeError: ‘Stduent‘ object has no attribute ‘age‘複製代碼setattr:設定對象的屬性值複製代碼>>> class Student:    def __init__(self,name):        self.name = name        >>> a = Student(‘Kim‘)>>> a.name‘Kim‘>>> setattr(a,‘name‘,‘Bob‘)>>> a.name‘Bob‘複製代碼delattr:刪除對象的屬性複製代碼#定義類A>>> class A:    def __init__(self,name):        self.name = name    def sayHello(self):        print(‘hello‘,self.name)#測試屬性和方法>>> a.name‘小麥‘>>> a.sayHello()hello 小麥#刪除屬性>>> delattr(a,‘name‘)>>> a.nameTraceback (most recent call last):  File "<pyshell#47>", line 1, in <module>    a.nameAttributeError: ‘A‘ object has no attribute ‘name‘複製代碼callable:檢測對象是否可被調用複製代碼>>> class B: #定義類B    def __call__(self):        print(‘instances are callable now.‘)        >>> callable(B) #類B是可調用對象True>>> b = B() #調用類B>>> callable(b) #執行個體b是可調用對象True>>> b() #調用執行個體b成功instances are callable now.複製代碼   變數操作 globals:返回當前範圍內的全域變數和其值組成的字典>>> globals(){‘__spec__‘: None, ‘__package__‘: None, ‘__builtins__‘: <module ‘builtins‘ (built-in)>, ‘__name__‘: ‘__main__‘, ‘__doc__‘: None, ‘__loader__‘: <class ‘_frozen_importlib.BuiltinImporter‘>}>>> a = 1>>> globals() #多了一個a{‘__spec__‘: None, ‘__package__‘: None, ‘__builtins__‘: <module ‘builtins‘ (built-in)>, ‘a‘: 1, ‘__name__‘: ‘__main__‘, ‘__doc__‘: None, ‘__loader__‘: <class ‘_frozen_importlib.BuiltinImporter‘>}locals:返回當前範圍內的局部變數和其值組成的字典複製代碼>>> def f():    print(‘before define a ‘)    print(locals()) #範圍內無變數    a = 1    print(‘after define a‘)    print(locals()) #範圍內有一個a變數,值為1    >>> f<function f at 0x03D40588>>>> f()before define a {} after define a{‘a‘: 1}複製代碼   互動操作 print:向標準輸出對象列印輸出>>> print(1,2,3)1 2 3>>> print(1,2,3,sep = ‘+‘)1+2+3>>> print(1,2,3,sep = ‘+‘,end = ‘=?‘)1+2+3=?input:讀取使用者輸入值>>> s = input(‘please input your name:‘)please input your name:Ain>>> s‘Ain‘   檔案操作 open:使用指定的模式和編碼開啟檔案,返迴文件讀寫對象# t為文本讀寫,b為二進位讀寫>>> a = open(‘test.txt‘,‘rt‘)>>> a.read()‘some text‘>>> a.close()   編譯執行 compile:將字串編譯為代碼或者AST對象,使之能夠通過exec語句來執行或者eval進行求值複製代碼>>> #流程語句使用exec>>> code1 = ‘for i in range(0,10): print (i)‘>>> compile1 = compile(code1,‘‘,‘exec‘)>>> exec (compile1)0123456789>>> #簡單求值運算式用eval>>> code2 = ‘1 + 2 + 3 + 4‘>>> compile2 = compile(code2,‘‘,‘eval‘)>>> eval(compile2)10複製代碼eval:執行動態運算式求值>>> eval(‘1+2+3+4‘)10exec:執行動態語句塊>>> exec(‘a=1+2‘) #執行語句>>> a3repr:返回一個對象的字串表現形式(給解譯器)>>> a = ‘some text‘>>> str(a)‘some text‘>>> repr(a)"‘some text‘"   裝飾器 property:標示屬性的裝飾器複製代碼>>> class C:    def __init__(self):        self._name = ‘‘    @property    def name(self):        """i‘m the ‘name‘ property."""        return self._name    @name.setter    def name(self,value):        if value is None:            raise RuntimeError(‘name can not be None‘)        else:            self._name = value            >>> c = C()>>> c.name # 訪問屬性‘‘>>> c.name = None # 設定屬性時進行驗證Traceback (most recent call last):  File "<pyshell#84>", line 1, in <module>    c.name = None  File "<pyshell#81>", line 11, in name    raise RuntimeError(‘name can not be None‘)RuntimeError: name can not be None>>> c.name = ‘Kim‘ # 設定屬性>>> c.name # 訪問屬性‘Kim‘>>> del c.name # 刪除屬性,不提供deleter則不能刪除Traceback (most recent call last):  File "<pyshell#87>", line 1, in <module>    del c.nameAttributeError: can‘t delete attribute>>> c.name‘Kim‘複製代碼classmethod:標示方法為類方法的裝飾器複製代碼>>> class C:    @classmethod    def f(cls,arg1):        print(cls)        print(arg1)        >>> C.f(‘類對象調用類方法‘)<class ‘__main__.C‘>類對象調用類方法>>> c = C()>>> c.f(‘類執行個體對象調用類方法‘)<class ‘__main__.C‘>類執行個體對象調用類方法複製代碼staticmethod:標示方法為靜態方法的裝飾器複製代碼# 使用裝飾器定義靜態方法>>> class Student(object):    def __init__(self,name):        self.name = name    @staticmethod    def sayHello(lang):        print(lang)        if lang == ‘en‘:            print(‘Welcome!‘)        else:            print(‘你好!‘)            >>> Student.sayHello(‘en‘) #類調用,‘en‘傳給了lang參數enWelcome!>>> b = Student(‘Kim‘)>>> b.sayHello(‘zh‘)  #類執行個體對象調用,‘zh‘傳給了lang參數zh你好

  

Python內建函數詳解——總結篇

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.