python self
‘‘‘self代表类的实例,而非类哪个对象调用方法,那么该方法中的self就代表那个对象self.__class__ 代表类名_‘‘‘class Person(object): def run(self): print("run") print(self.__class__) p = self.__class__("tt", 30, 10, 30) print(p) def eat(self, food): print("eat " + food) def say(self): print("Hello! my name is %s, I am %d years old" % (self.name, self.age)) #self不是关键字,换成其他的标识符也是可以的,但是帅的人都是用self def play(a): print("play " + a.name) def __init__(self, name, age, height, weight): self.name = name self.age = age self.height = height self.weight = weightper1 = Person("tom", 20, 160, 80)per1.say()per2 = Person("hanmeimei", 21, 160, 80)per2.say()per1.play()per1.run()
相关推荐
FlySky 2020-11-02
逍遥友 2020-10-26
taiyangshenniao 2020-10-05
flycony 2020-09-23
jacktangj 2020-09-18
YENCSDN 2020-09-15
lsjweiyi 2020-09-14
digwtx 2020-09-14
拾毅者 2020-09-14
zlxcsdn 2020-09-13
weiiron 2020-08-17
amazingbo 2020-08-16
郗瑞强 2020-08-16
lispython 2020-08-16
fengling 2020-08-15
xiesheng 2020-08-02
葫芦小金刚 2020-07-28
StevenSun空间 2020-07-26