小编fam*_*l42的帖子

Python 3使用__str__继承多个类

我如何使用__str__其他类的多个?例如:

class A:
    def __str__(self):
        return "this"

class B:
    def __str__(self):
        return "that"

class C(A,B):
    def __str__(self):
        return super(C, self).__str__() + " those"
        # return something(A) + " " something(B) + " those"

cc = C()
print(cc)
Run Code Online (Sandbox Code Playgroud)

输出:这些

我希望输出为:这就是那些

这篇文章几乎是一个解决方案(有super())

python string inheritance class python-3.x

0
推荐指数
1
解决办法
205
查看次数

标签 统计

class ×1

inheritance ×1

python ×1

python-3.x ×1

string ×1