operator-overloading - 谁能告诉我这段代码是如何工作的?
问题描述
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)
解决方案
推荐阅读
- javascript - 告诉 Vue 查看文件夹中的所有图片而不更改图片名称
- ios - 快速通道匹配创建后如何将配置文件设置为 Xcode 项目?
- mockito - PowerMockito 在定义第二个“when”子句时调用 Mocked Object 上的真实方法
- python - 从 Oct2Py 返回类对象
- python - CloudFunction 创建的数据流作业上的 ModuleNotFoundError
- json - 无法在 Ionic 4 ANGULAR 中显示 json 数据
- sql - 加入 2 个表并将特定记录置于顶部
- symfony4 - 如何使用 symfony 邮件程序将图像附加到电子邮件中?
- python - 如何为 pyside2 / pyqt 脚本禁用 macOS 暗模式?
- flutter - Flutter中如何实现对Dismissible widget的删除和撤消操作?