Duck Typing

Oren Tirosh oren-py-l at hishome.net
Tue Sep 16 09:51:15 EDT 2003


On Tue, Sep 16, 2003 at 02:01:18AM -0700, srijit at yahoo.com wrote:
> Hello All,
> I have been seeing this term "duck typing" for quite sometime now. It
> will be nice if one of us can give an example in Python demonstrating
> duck typing and/or link to some Python references.

class Duck:
    def quack(self):
        print "Quack!"

class MeWearingSillyDuckOutfit:
    def quack(self):
        print "ummm... Quack!"

def make_it_quack(obj):
    obj.quack()

a = Duck()
b = MeWearingSillyDuckOutfit()
make_it_quack(a)
make_it_quack(b)






More information about the Python-list mailing list