首页 > 解决方案 > 谁能告诉我这段代码是如何工作的?

问题描述

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)

标签: operator-overloadingmagic-methods

解决方案


推荐阅读