[Python] 先宣告再定義, Interface

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 = ...

Last Updated on 2026/01/30 by A1go

目錄
Bitnami