class parent(): i=1 __j=2 class child(parent): m=3 __n=4 def __init__(self,age,name): self.age=age self.name=name def des(self): print(self.name,self.age) c=child("wang",18) c.des() #通过对象可以访问类公有属性m与父类公有属性i 不能访问类的私有属性__n和父类私有属性_j print(c.i) # print(c.__j) print(c.m) # print(c.__n) #通过类可以访问类公有属性 print(child.i,child.m) #通过类无法访问实例属性 #print(child.age,child.name) --------------------- 转载: 原文:https://blog.csdn.net/weixin_37763484/article/details/83312996