1 class Animal: 2 def eat(self): 3 print("吃") 4 5 def drink(self): 6 print("喝") 7 8 def run(self): 9 print("跑") 10 11 def sleep(self): 12 print("睡") 13 14 class Dog(Animal): 15 defBark (Self): 16 Print ( " call " ) 17 18 class XiaoTianQuan (Dog): 19 DEF Fly (Self): 20 Print ( " Fly " ) 21 22 # DEF Bark (Self): 23 # Print ( "like God mooing ") 24 # 25 # # call the parent class method bark 26 # Super (). bark () 27 # 28 # # extension 29 # Print ("! @ # $ @@ (* U! ( ") 30 31 #python2.x expansion and rewriting 32 DEF Bark (Self): 33 is 34 is Print ( " like God called " ) 35 36 Dog.bark (Self) 37 [ 38 is Print ( " @ # @ # $ @ R & lt " ) 39 40 = XTQ XiaoTianQuan () 41 is xtq.eat () 42 is xtq.bark () 43 is xtq.fly ()
Eat like God called called @ # $ @ # R @ Fly