python类的对象使用

class student():
    def __init__(self,age,sex):
        self.age = age
        self.sex = sex  #self.__sex =sex 表示私有化
    def missing(self):
        if self.age =='':
            print("no")
        else:
            print("yes")
class person():
    def __init__(self):
         self.age = 18.0
         self.sex = 'm'
         self.gradyer = 2006
    def p(self):
         print(self.age)

p1 = person()
p1.p()
print(p1.sex)

posted @ 2018-04-11 08:20  Python研究者  阅读(355)  评论(0编辑  收藏  举报