1、Python中类的学习

1、Python中类的学习

class student:   #定义类
    student_count=0   #定义类变量

    def __init__(self, name, age):  #类的初始化
        self.name = name
        self.age = age
        student.student_count += 1

    def  dis_student(self):   #定义类的实例
        print("student name is "+self.name,'student_age is '+self.age)

student1 = student('zhang', '25')
student2 = student('chen', '36')
student1.dis_student()
student2.dis_student()
print(student.student_count)

1、Python中类的学习

#子类 父类的定义
class people:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    def dis_name(self):
        print('her name is ', self.name)
    def dis_age(self):
        print('her age is ', self.age)
class student(people):
    def __init__(self,name,age,school):
        self.name = name
        self.age = age
        self.school = school
    def dis_school(self):
        print('her school is ',self.school)

Student=student('zhang','23','wcxx')
Student.dis_age()
Student.dis_name()
Student.dis_school()

上一篇:纯RAW数据转换为DNG格式


下一篇:vue学习---组件的几个注意点(组件名, 组件标签, 简写方式)