Python的 类

class定义:
class School:  #父类
# class Student(School)  #子类
构造函数def:
__foo__ :#定义特殊方法,系统定义名字 类似__init__(self)
_foo :#定义protected 保护变量 保护类型只允许本身和子类进行访问。不能用from module imort *
__foo:定义private 私有变量 只能允许这个类本身进行访问

def __init__(self,x,y)
	self.Student = x
	self.Teacher = y
	
def setStudentNum(self,num)
	self.Student = num

school = School(123,123) #实例化父类
# S = Student() #实例化子类
school.setStudentNum(123) #调用父类方法
发布了41 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43472877/article/details/90139781
今日推荐