Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Test:
- pass
- obj = Test()
- print(' str:', obj)
- print('repr:', repr(obj))
- # str: <__main__.Test object at 0x7fbdab39d128>
- # repr: <__main__.Test object at 0x7fbdab39d128>
- # ------------------------------------------------
- class Test:
- def __str__(self):
- return "Hello"
- obj = Test()
- print(' str:', obj)
- print('repr:', repr(obj))
- # str: Hello
- # repr: <__main__.Test object at 0x7fbdab46c518>
- # ------------------------------------------------
- class Test:
- def __str__(self):
- return "Hello"
- def __repr__(self):
- return "Good Bye"
- obj = Test()
- print(' str:', obj)
- print('repr:', repr(obj))
- # str: Hello
- # repr: Good Bye
- # ------------------------------------------------
- class Test:
- def __repr__(self):
- return "Good Bye"
- obj = Test()
- print(' str:', obj)
- print('repr:', repr(obj))
- # str: Good Bye
- # repr: Good Bye
Add Comment
Please, Sign In to add comment