Duck Type 鴨子類型

Duck Typing is a [type system] used in dynamic languages. For example, Python, Perl, Ruby, PHP, Javascript, etc. where the type or the class of an object is less important than the method it defines. Using Duck Typing, we do not check types at all. Instead, we check for the presence of a given method or attribute.

reference: geeksforgeeks

按上述來說, 鴨子類型是動(dòng)態(tài)語(yǔ)言的特性, 在動(dòng)態(tài)語(yǔ)言中, 類型并不重要, 重要的是類型(實(shí)例)的方法

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 什么是鴨子類型? 一個(gè)對(duì)象有效的語(yǔ)義,不是由繼承自特定的類或?qū)崿F(xiàn)特定的接口,而是由"當(dāng)前方法和屬性的集合"決定。 ...
    linheimx閱讀 1,370評(píng)論 0 1
  • Fluent Python Notebook Part Three 標(biāo)簽(空格分隔): Python Object...
    plutoese閱讀 1,980評(píng)論 0 50
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,854評(píng)論 0 10
  • 函數(shù)與命名空間 函數(shù)的全局命名空間始終是定義該函數(shù)的模塊,而不是調(diào)用該函數(shù)的命名空間。 函數(shù)及其全局命名空間決定了...
    縱橫嘆閱讀 482評(píng)論 0 2
  • 4.8. Binary Sequence Types — bytes, bytearray, memoryview...
    xpf2000閱讀 5,546評(píng)論 0 1

友情鏈接更多精彩內(nèi)容