Skip to content

Instantly share code, notes, and snippets.

@drhanlau
Created March 2, 2016 08:26
Show Gist options
  • Save drhanlau/476c09f90a81b178eab1 to your computer and use it in GitHub Desktop.
Save drhanlau/476c09f90a81b178eab1 to your computer and use it in GitHub Desktop.
Duck Typing
class Duck:
def quack(self):
print("Quaaaaaack!")
def feathers(self):
print("The duck has white and gray feathers.")
class Person:
def quack(self):
print("The person imitates a duck.")
def feathers(self):
print("The person takes a feather from the ground and shows it.")
def name(self):
print("John Smith")
def in_the_forest(duck):
duck.quack()
duck.feathers()
def game():
donald = Duck()
john = Person()
in_the_forest(donald)
in_the_forest(john)
game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment