Advertisement
here2share

# duck_typing.py

Jun 12th, 2021
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # duck_typing.py
  2.  
  3. # If it walks like a duck, and it quacks like a duck, then it must be a duck.
  4.  
  5. class Duck():
  6.  
  7.     def walk(self):
  8.         print("Look like a duck is walking")
  9.  
  10.     def talk(self):
  11.         print("This duck is quacking")
  12.  
  13. class Chicken():
  14.  
  15.     def walk(self):
  16.         print("Look like a chicken is walking")
  17.  
  18.     def talk(self):
  19.         print("This chicken is clucking")
  20.  
  21. class Person():
  22.  
  23.     def catch(self, subject):
  24.         subject.walk()
  25.         subject.talk()
  26.         print("You caught the little critter!")
  27.  
  28.  
  29. duck = Duck()
  30. chicken = Chicken()
  31. person = Person()
  32.  
  33. person.catch(chicken)
  34. print
  35. person.catch(duck)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement