t376.py 345 B

123456789101112131415161718192021
  1. class HasLen:
  2. def __init__(self, l):
  3. self.l = l
  4. def __len__(self):
  5. return self.l
  6. class SubLen(HasLen):
  7. def __init__(self, l):
  8. HasLen.__init__(self, l)
  9. class NoLen:
  10. def __init__(self, l):
  11. self.l = l
  12. h = HasLen(42)
  13. print len(h)
  14. h2 = SubLen(43)
  15. print len(h2)
  16. h3 = NoLen(44)
  17. print len(h3)