1. 程式人生 > >__str__和__repr__有啥區別呢?

__str__和__repr__有啥區別呢?

>>> class Item(): ...     def __init__(self): ...         self.code = '' ...         self.data = '' ...     def __str__(self): ...         """ support a nice string representation with all attribute values""" ...         return 'caonimabi' ...     def __repr__(self): ...         return 'caonimaligebi' ...  >>> a=Item() >>> a caonimaligebi >>> print a caonimabi 請忽視拼音含義,因為team裡有個sb裝逼,對他說的