Advertisement
VikkaLorel

class attribute with Inheritance

Sep 30th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. class AAA(object):
  2.     x = 1
  3.  
  4.  
  5. class BBB(AAA):
  6.     pass
  7.  
  8.  
  9. class CCC(AAA):
  10.     pass
  11.  
  12.  
  13. if __name__ == '__main__':
  14.     # AAA: {'x': 1}, BBB: {}, CCC: {}
  15.     print(AAA.x, BBB.x, CCC.x)
  16.     BBB.x = 2
  17.     # AAA: {'x': 1}, BBB: {'x': 2}, CCC: {}
  18.     print(AAA.x, BBB.x, CCC.x)
  19.     AAA.x = 3
  20.     # AAA: {'x': 3}, BBB: {'x': 2}, CCC: {}
  21.     print(AAA.x, BBB.x, CCC.x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement