class2.py 362 B

1234567891011121314151617181920212223242526
  1. # class with __init__
  2. class C1:
  3. def __init__(self):
  4. self.x = 1
  5. c1 = C1()
  6. print(type(c1) == C1)
  7. print(c1.x)
  8. class C2:
  9. def __init__(self, x):
  10. self.x = x
  11. c2 = C2(4)
  12. print(type(c2) == C2)
  13. print(c2.x)
  14. # __init__ should return None
  15. class C3:
  16. def __init__(self):
  17. return 10
  18. try:
  19. C3()
  20. except TypeError:
  21. print('TypeError')