Something more beautiful than <__main__.MyClass instance at 0x1624710>

后端 未结 2 716
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 09:38

This is my class (as simple as it can be):

class MyClass():
    def __init__(self, id):
        self.id = id

    def __str__(self):
        return \"MyClass         


        
2条回答
  •  迷失自我
    2021-01-18 09:49

    >>> class MyClass():
    ...     def __init__(self, id):
    ...         self.id = id
    ...     def __repr__(self):
    ...         return "MyClass #%d" % self.id
    ... 
    >>> c = MyClass(5)
    >>> c
    MyClass #5
    

提交回复
热议问题