关于Python的self指向性

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()

 

posted @ 2015-12-16 15:59  chiocai  阅读(317)  评论(0编辑  收藏  举报