谁能告诉我这段代码是如何工作的?

时间:2021-04-11 15:55:26

标签: operator-overloading magic-methods

class SpecialString:
    def __init__(self, cont):
        self.cont = cont

    def __truediv__(self, other):
        line = "=" * len(other.cont)
        return "\n".join([self.cont, line, other.cont])

spam = SpecialString("spam")
hello = SpecialString("Hello world!")
print(spam / hello)

0 个答案:

没有答案