python 實現(xiàn)類重載(類似C#的類重載,但是遠不如C#的類重載好用)
pip install multipledispatch -i https://mirrors.aliyun.com/pypi/simple
from multipledispatch import dispatch class MyClass: ab = 11234 def __init__(self): self.aa = 1 @dispatch() def calculate(self): self.aa = 1111 @dispatch(int) def calculate(self, a): self._calculate(a) @classmethod def _calculate(cls, ip): print(cls.ab) print(ip) obj = MyClass() obj.calculate() obj.calculate(5) print(obj.aa)

不多廢話,直接看代碼就行了,不知道百度一下就行了。
浙公網(wǎng)安備 33010602011771號