Duck Typing

Steve Holden sholden at holdenweb.com
Tue Sep 16 11:47:11 EDT 2003


"Oren Tirosh" <oren-py-l at hishome.net> wrote ...
> 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)
>

exquacktly [ducks and runs]

regards
-- 
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list