亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問寫兩遍instance有意義嗎?

請問寫兩遍instance有意義嗎?

撒科打諢 2023-03-18 13:09:37
本來是instance. methodname=types.MethodType(methodName,instance)我改成 methodname=types.MethodType(methodName,instance),即把開頭的instance. 去掉,不也能實現一樣的功能嗎,開頭的instance.是不是多余了啊,因為本來就是就是給參數2的instance綁定方法的,寫兩遍instance有意義嗎
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

在Python中,對這兩個東西有明確的規定:
函數function —— A series of statements which returns some value to a caller. It can also be passed zero or more arguments which may be used in the execution of the body.

方法method —— A function which is defined inside a class body. If called as an attribute of an instance of that class, the method will get the instance object as its first argument (which is usually called self).
從定義的角度上看,我們知道函數(function)就相當于一個數學公式,它理論上不與其它東西關系,它只需要相關的參數就可以。所以普通的在module中定義的稱謂函數是很有道理的。
那么方法的意思就很明確了,它是與某個對象相互關聯的,也就是說它的實現與某個對象有關聯關系。這就是方法。雖然它的定義方式和函數是一樣的。也就是說,在Class定義的函數就是方法。

查看完整回答
反對 回復 2023-03-21
  • 1 回答
  • 0 關注
  • 69 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號