Objects in Python

Website development, web apps, desktop/server apps, mobile apps and any other coding
Locked
Anonymous

Objects in Python

Post by Anonymous »

I am finding it difficult to implement polymorphism in Python...

Archived topic from Iceteks, old topic ID:4520, old post ID:36072
wtd
Posts: 157
Joined: Sat Sep 25, 2004 7:21 pm

Objects in Python

Post 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]
Locked