第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

查看python源碼,發(fā)現(xiàn)里面的函數(shù)都以pass結(jié)尾,那么意義何在?

查看python源碼,發(fā)現(xiàn)里面的函數(shù)都以pass結(jié)尾,那么意義何在?

慕村225694 2019-02-18 17:06:36
例如: 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'. """ 其中一個(gè)函數(shù) def capitalize(self): # real signature unknown; restored from __doc__ """ S.capitalize() -> str Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case. """ return "" 這個(gè)函數(shù)到底返回了什么?難道返回了一個(gè)空字符嗎? def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__ """ S.endswith(suffix[, start[, end]]) -> bool Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try. """ return False 這個(gè)函數(shù),返回False ,什么意思? def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__ """ S.find(sub[, start[, end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. """ return 0 這個(gè)返回一個(gè)0 ? def format(self, *args, **kwargs): # known special case of str.format """ S.format(*args, **kwargs) -> str Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces ('{' and '}'). """ pass 這個(gè)是一pass結(jié)尾的,那么要這個(gè)函數(shù)有什么意義 但是我在實(shí)際應(yīng)用他們的時(shí)候,返回的并不是這樣的? 我現(xiàn)在的以為是:這個(gè)類里面的這些函數(shù),函數(shù)體里面什么邏輯都沒(méi)有寫?那么函數(shù)是怎么運(yùn)行的?
查看完整描述

4 回答

?
白衣染霜花

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊

有些附帶注釋的接口是提供給用戶看的,告訴用戶如何使用,而源碼是被加密保護(hù)的,至于保護(hù)的手段,不同的人各有不同。除非完全開源,否則有的函數(shù)的實(shí)現(xiàn)代碼你是看不到的,你最多看到一些接口說(shuō)明。

查看完整回答
反對(duì) 回復(fù) 2019-03-01
?
慕勒3428872

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超6個(gè)贊

python是C語(yǔ)言實(shí)現(xiàn)的,盡管有很多標(biāo)準(zhǔn)庫(kù)是由python代碼實(shí)現(xiàn),但是涉及到底層支撐架構(gòu)的功能還是C代碼。一些IDE為了對(duì)這些進(jìn)行友好代碼提示,會(huì)弄和底層一樣的訪問(wèn)接口,而其實(shí)現(xiàn)直接寫 pass 略過(guò)。

另外,聽樓上 “此用戶無(wú)昵稱” 的意思是說(shuō)看不到是因?yàn)樵创a被加密保護(hù),這種觀點(diǎn)是不對(duì)的,cpython的代碼是開源的。

查看完整回答
反對(duì) 回復(fù) 2019-03-01
?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊

這個(gè)不是源碼、只是一個(gè)類似于“接口”的東西、只能從這里看到有哪些函數(shù)(方法)、都有些什么參數(shù)。

查看完整回答
反對(duì) 回復(fù) 2019-03-01
?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

底層是用c語(yǔ)言實(shí)現(xiàn)的,所以代碼并沒(méi)有真正的調(diào)用你貼的這些源碼。
但是這些源碼是非常有用的,因?yàn)楫?dāng)你help(str)的時(shí)候,他們會(huì)顯示出來(lái)。目的就是每個(gè)函數(shù)是做什么的,通過(guò)注釋反射實(shí)現(xiàn)文檔的一種方式。
比如下面定義的函數(shù)

def func(a: int, b: str):
    return b * a

int和str并沒(méi)有任何作用,但是當(dāng)你用inspect.getfullargspec(func).annotations的時(shí)候能看到每個(gè)變量的定義一樣,當(dāng)然定義除了可以是類,還可以是函數(shù),常量等。

查看完整回答
反對(duì) 回復(fù) 2019-03-01
  • 4 回答
  • 0 關(guān)注
  • 645 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)