DreamWorks

Never say Never。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Python中self的使用

Posted on 2013-07-11 13:14  _Babyface  阅读(428)  评论(0编辑  收藏  举报

python中的self相当于C++中的this指针,指示的是其本身对象

例如

 1 high = 172
 2 
 3 class PrintIn:
 4     def __init__(self,high1):
 5         self.high = high1
 6         if(self.high < 160):
 7             print "haaa,So short that you don't do this job"
 8             return
 9         elif(self.high > 200):
10             print "Mother fucker,are you Yao Ming?"
11         else:
12             print "O'ye,you can do this job very well"
13     def printInfo(self,age1):
14         self.age = age1
15         print (self.age,self.high)
16         
17 if __name__ == '__main__':
18     p = PrintIn(201)
19     p.printInfo(26)
20 ''' 
21     PrintIn.printInfo(p,26)
22 '''