python 类的字符串显示

2019-12-12 18:04:15 浏览数 (1)

class Pair: def init(self, x, y): self.x = x self.y = y

代码语言:javascript复制
def __repr__(self):
    return 'Pair({0.x!r}, {0.y!r})'.format(self)

def __str__(self):
    return '({0.x!s}, {0.y!s})'.format(self)

0 人点赞