Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A:
- def __init__(self, rid, title):
- self.rid = rid
- self.title = title
- self.b = []
- def __add__(self, other):
- if type(other) == B:
- self.b += [other]
- def __str__(self):
- return self.rid + ' - ' + self.title
- def __repr__(self):
- return str(self)
- class B:
- def __init__(self, rid, title):
- self.rid = rid
- self.title = title
- b = B('123', 'abc')
- a = A('345', 'cde')
- print(a)
- a += b
- print(a)
- 345 - cde
- None
Add Comment
Please, Sign In to add comment