Guest User

Untitled

a guest
Nov 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. class A:
  2. def __init__(self, rid, title):
  3. self.rid = rid
  4. self.title = title
  5. self.b = []
  6.  
  7. def __add__(self, other):
  8. if type(other) == B:
  9. self.b += [other]
  10.  
  11. def __str__(self):
  12. return self.rid + ' - ' + self.title
  13.  
  14. def __repr__(self):
  15. return str(self)
  16.  
  17. class B:
  18. def __init__(self, rid, title):
  19. self.rid = rid
  20. self.title = title
  21.  
  22. b = B('123', 'abc')
  23. a = A('345', 'cde')
  24.  
  25. print(a)
  26.  
  27. a += b
  28.  
  29. print(a)
  30.  
  31. 345 - cde
  32.  
  33. None
Add Comment
Please, Sign In to add comment