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

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

請(qǐng)問為什么bool是int的子類?

請(qǐng)問為什么bool是int的子類?

牛魔王的故事 2019-09-05 10:05:23
為什么bool是int的子類?當(dāng)通過python-memcached在memcached中存儲(chǔ)bool時(shí),我注意到它以整數(shù)形式返回。檢查庫(kù)的代碼向我顯示有一個(gè)地方isinstance(val, int)被檢查以將值標(biāo)記為整數(shù)。所以我在python shell中測(cè)試了它并注意到以下內(nèi)容:>>> isinstance(True, int)True>>> issubclass(bool, int)True但為什么究竟是bool一個(gè)子類int呢?它有點(diǎn)意義,因?yàn)椴紶栔祷旧鲜且粋€(gè)int,它可以只取兩個(gè)值,但它需要比實(shí)際整數(shù)少得多的操作/空間(沒有算術(shù),只有一點(diǎn)存儲(chǔ)空間)....
查看完整描述

3 回答

?
守候你守候我

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

參見PEP 285 - 添加bool類型。相關(guān)段落:

6)bool應(yīng)該繼承自int嗎?

=>是的。

在理想的世界中,bool可能更好地實(shí)現(xiàn)為一個(gè)知道如何執(zhí)行混合模式算術(shù)的單獨(dú)整數(shù)類型。但是,從int繼承bool可以極大地簡(jiǎn)化實(shí)現(xiàn)(部分原因是所有調(diào)用PyInt_Check()的C代碼都將繼續(xù)工作 - 這對(duì)于int的子類返回true。



查看完整回答
反對(duì) 回復(fù) 2019-09-07
?
慕娘9325324

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

也可以help用來檢查Bool控制臺(tái)中的值:

幫助(真)

help(True)Help on bool object:class bool(int)
 |  bool(x) -> bool |  
 |  Returns True when the argument x is true, False otherwise.
 |  The builtins True and False are the only two instances of the class bool.
 |  The class bool is a subclass of the class int, and cannot be subclassed.
 |  
 |  Method resolution order:
 |      bool |      int |      object |

幫助(假)

help(False)Help on bool object:class bool(int)
 |  bool(x) -> bool |  
 |  Returns True when the argument x is true, False otherwise.
 |  The builtins True and False are the only two instances of the class bool.
 |  The class bool is a subclass of the class int, and cannot be subclassed.
 |  
 |  Method resolution order:
 |      bool |      int |      object



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

添加回答

舉報(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)