@
1.説明
Pythonの属性:type属性、インスタンスのプロパティの
メソッド:クラスメソッド、インスタンスメソッド、静的メソッドは、
クラスのプロパティを変更したい、クラスメソッドのみ、内部のCLSへの唯一のクラスメソッド(クラス)の着信データため
の静的メソッドは、普通です便宜のみのための方法
方法の例は、直接=自己することができるオブジェクト名を呼び出すためにクラスを呼び出すことができない
、以下の詳細
2.コード
class Provice(object):
#类属性
country = "china"
def __init__(self,name):
#实例属性
self.name = name
def self_control(self):
print("我是实例方法,我必须有self",self.name)
@staticmethod
def static_method():
#由类调用,无默认参数
print("我是static_method")
@classmethod
def class_method(cls):
print("我是classmethod++",cls.country)
cls.country = "china___"
sichuan = Provice("sichuan")
print(sichuan.name,sichuan.country,Provice.country)
Provice.class_method()
Provice.static_method()
Provice.self_control(sichuan)
sichuan.static_method()
print(sichuan.name,sichuan.country,Provice.country)
著者について
個人のブログサイト
の個人GitHubのアドレス
個々のパブリック数: