How to properly implement/overload “__repr__ ”?

前端 未结 3 1474
我在风中等你
我在风中等你 2021-01-26 00:27

New to python and this might be a silly question, but how does one properly implement the repr method?

I wrote a quick little program to simulate a game of card

3条回答
  •  攒了一身酷
    2021-01-26 00:31

    __repr__ ideally could return the representation of the object that you would use to create this instance.

    From repr():

    For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object.

提交回复
热议问题