2024-04-25 11:41:27 发布
网友
我有一个classA,当我试图调用classB中的矩阵在控制台上打印出来时,我有一个get方法来获取更新后的矩阵。我有点像
<packageA.prod.Cell.CellClass instance at 0x02C55558>, <packageA.prod.Cell.CellClass instance at 0x02C55580>,
如何将存储在该位置的值打印出来?你知道吗
如何拆分这些值,因为我得到了一个这样的值列表,而列表不能拆分
必须在类中实现__repr__方法。示例:
__repr__
class CellClass: def __init__(self, value): self.value = value def __repr__(self): return 'Cell value: %s' % (self.value) c = CellClass('cell text')
输出:
In [2]: c Out[2]: Cell value: cell text
信用证/进一步证明: Purpose of Python's __repr__
必须在类中实现
__repr__
方法。示例:输出:
信用证/进一步证明: Purpose of Python's __repr__
相关问题 更多 >
编程相关推荐