Python的self是指向类的实例化对像,而不是类本身,每次调用类的实例化即self指向此实例化对像,如下代码;
1 class Person: 2 def __init__(self,name): 3 self.name=name 4 def sayhello(self): 5 print (‘My name is:‘,self.name) 6 7 p=Person(‘Bill‘) 8 P1=Person(‘APLEE‘) 9 print p.sayhello() 10 print P1.sayhello()
时间: 2024-10-10 04:46:42