面向对象是Python的核心编程范式。
类与对象
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
raise NotImplementedError继承与多态
class Dog(Animal):
def speak(self):
return f'{self.name} says Woof!'魔术方法
class Vector:
def __add__(self, other):
return Vector(self.x + other.x, self.y + other.y)
评论 (0)
暂无评论,来发表第一条评论吧!
发表评论