标签:实例 方法 初始化 from inf count class nat highlight
class persion: def info (self,name,age): print "Your name is %s,you are %s years old" %(name,age) P=persion() P.info(‘TOM‘,25)
类和函数的区别就是,多一个参数 self, 指对象本身。
实例:
方法:
类的初始化
class persion: def __init__(self,nationnality): self.country=nationnality def info (self,name,age): print "Your name is %s,you are %s years old, you are from %s" %(name,age,self.country) P=persion(‘CHINA‘) P.info(‘TOM‘,25)
标签:实例 方法 初始化 from inf count class nat highlight
原文地址:http://www.cnblogs.com/long2-20160310/p/7532122.html