首页 > 编程语言 > 详细

Python 类

时间:2017-02-05 12:28:43      阅读:122      评论:0      收藏:0      [点我收藏+]
#coding:utf-8
class people():
  #基本属性
    name = "hostname"
    age =  2
  #私有属性
    __weight = 0
    def __init__(self,n,a,w):
        self.name = n
        self.age = a
        self.__weight = w 

    def aa(self):
        print "hello wold"
    def speak(self):
        print "%s is speaking I am %d years old"  %(self.name,self.age)
class student(people):
    def __init__(self,n,a,w,g):
        #继承类中的构建函数,参数
        people.__init__(self,n,a,w)
        self.grade = g 
        #可覆盖继承类中的方法
    def speak(self):     
            print "%s is speaking: I am %d years old,and I am in grade %d"%(self.name,self.age,self.grade)
a = student(tom,25,30,32)
a.speak()
a.aa()

 

Python 类

原文:http://www.cnblogs.com/lliqiang/p/6367286.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!