【发布时间】:2021-04-02 11:02:25
【问题描述】:
尝试了force-implementing-specific-attributes-in-subclass的答案
但不起作用。这段代码仍然没有错误地通过。
#python version: 3.8.1
from abc import ABC, abstractmethod
class A(ABC):
@property
@abstractmethod
def pr(self):
return 0
class B(A):
def pr(self):# not a property.
return 5
b = B()
print(b.pr())
那么我怎样才能强制子类实现特定的属性(pr as above)?
【问题讨论】:
标签: python inheritance properties subclass abstract-methods