Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # duck_typing.py
- # If it walks like a duck, and it quacks like a duck, then it must be a duck.
- class Duck():
- def walk(self):
- print("Look like a duck is walking")
- def talk(self):
- print("This duck is quacking")
- class Chicken():
- def walk(self):
- print("Look like a chicken is walking")
- def talk(self):
- print("This chicken is clucking")
- class Person():
- def catch(self, subject):
- subject.walk()
- subject.talk()
- print("You caught the little critter!")
- duck = Duck()
- chicken = Chicken()
- person = Person()
- person.catch(chicken)
- print
- person.catch(duck)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement