Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. >>> r'hello"world'
  2. 'hello\"world'
  3.  
  4. >>> print(r'hello"world')
  5. hello"world
  6.  
  7. class My:
  8. def __str__(self):
  9. return '__str__: Вызывается для print'
  10. def __repr__(self):
  11. return '__repr__: Вызывается в интерактивном режиме'
  12.  
  13. obj = My()
  14. print(obj)
  15.  
  16. >>> obj
  17. __repr__: Вызывается в интерактивном режиме
  18.  
  19. >>> a = r'hello"world'
  20. >>> a #равносильно вызову print(a.__repr__())
  21. 'hello\"world'
  22. >>> print(a) #равносильно вызову print(a.__str__())
  23. hello"world
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement