[Python] 先宣告再定義, Interface
- 2026.01.30
- Uncategorized
Function
def func(...): pass ... def func(...): ...
Method
Method 先宣告再定義
class Cls:
def method(self, ...):
pass
...
def func(self, ...):
...
Cls.method=func
Abstract Method (Interface)
from abc import ABC, abstractmethod
from typing import ClassVar
class If(ABC):
@abstractmethod
def method(self, ...)[ -> ...]:
pass
attr: ClassVar[<type>][ = <default_value>]
class Cls(If):
def method(self, ...):
pass
attr = ...
->: function return type annotationtyping.ClassVar
Last Updated on 2026/01/30 by A1go