Advertisement
ivandrofly

Python - Inheritance and Override

Jan 31st, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. class one(object): # this will inherit object
  2.     def __int__(self):
  3.         self.x = 10
  4.     def makep(self):
  5.         self.p = 3.12
  6.  
  7. class two(object):
  8.     def __init__(self):
  9.         self.y =20
  10.     def maked(self):
  11.         self.d = 13
  12.        
  13. class book(two, one): # Python supports mult-inheritance
  14.     def pr(self):
  15.         print("%d, %d, %d, %d" % (self.d, self.p, self.y, self.x)) #this will fail
  16.  
  17. novel = book() # this will create instance of book() classe
  18. print(novel.makep())
  19. print(novel.maked())
  20. print(novel.p)
  21. print(novel.d)
  22. #print(novel.pr()) # this shall fail
  23. input() # wait here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement