Python的面向对象编程:把一组数据结构和处理他们的方法组成对象(object),把相同行为的对象归纳为类(class),通过类的封装(encapsulation)隐藏内部细节,通过继承(inheritance)实现类的特化(specification)/泛化(generalization),通过多态(polymorphism)实现基于对象类型的动态分派(dynamic dispatch)。
In [4]:
class Student(object):
def __init__(self, score):
self.__score = score
def print_score(self):
print('The score is %d' %self.__score)
student = Student(90)
student.print_score()
print(student._Student__score)
print(student.__score)
In [ ]: