屬性和方法

淡然。。發表於2024-06-20

class Student(object):

# 類屬性

school = '新華小學'

def init(self,name):

self.name = name

#方法

def say(self):

print('hahaha')

def show_student_info(self):

print(self.school,self.name)

class Student1(Student):

def init(self,age,name):

super().init(name)

self.__age = age

def show_student_info(self):

print(self.name,self.__age)

def del(self):

print('over')

stu1 = Student1(12,'李四')

stu1.show_student_info()

相關文章