Page 1 of 1

Objects in Python

Posted: Mon Aug 28, 2006 5:00 am
by Anonymous
I am finding it difficult to implement polymorphism in Python...

Archived topic from Iceteks, old topic ID:4520, old post ID:36072

Objects in Python

Posted: Sat Sep 02, 2006 9:40 am
by wtd
How so?

Code: Select all

class Dog(object):
   def bark(self):
      return "Ruff!"

class Tree(object):
   def bark(self):
      return "Rough!"

def speak(obj):
   print obj.bark()

fido = Dog()
leafy = Tree()
say(fido)
say(leafy)[code] 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:4520, old post ID:36099[/size][/color]