【发布时间】:2020-06-02 21:17:15
【问题描述】:
我正在查看 python 的语法,并且您可以在继承中使用海象运算符!不信,我试了一下:
class foo: pass
class bar(foobar := foo):
def x(self):
print("it works!")
b = bar()
b.x()
这不会引发 any 语法错误(python 3.8.2)!它有什么用,它是如何工作的?
【问题讨论】:
-
不一定是有原因的。没有人需要根据用例的存在来明确决定是否允许一起使用两个东西。各种各样的东西都可以用无用的方式组合起来。
标签: python class oop inheritance walrus-operator