Python在oop方面思想和Ruby一样。同样包括数据封装,继承和多态三大特点。
Python的类提供了面向对象编程的所有标准特性:
例子:
class Student(object): """docstring for Student.""" def __init__(self, name, score): super(Student, self).__init__() self.name = name self.score = score def print_score(self): print(‘%s %s‘ % (self.name, self.score)) bart = Student(‘Bart Simpson‘, 59) lisa = Student(‘Lisa Simpson‘, 87) bart.print_score() lisa.print_score()
原文:https://www.cnblogs.com/chentianwei/p/11821951.html