query regarding OOP functionality in python
goodger at python.org
Mon Apr 5 20:23:57 CEST 2004
Vardhman Jain wrote:
> Could someone tell me, what kind of polymorphisms does python
According to FOLDOC (http://foldoc.doc.ic.ac.uk):
In object-oriented programming, the term [polymorphism] is used to
describe a variable that may refer to objects whose class is not
known at compile time and which respond at run time according to
the actual class of the object to which they refer.
Python fully supports this definition of polymorphism. Python also
supports "ad-hoc polymorphism" (a.k.a. operator overloading), and
parametric polymorphism, as described on the FOLDOC page for
> Does it allow multiple functions with same name and different
No, Python does not support "function overloading".
> Does it allow multiple functions with same name but
> different return types.
No. Python only allows one object to be bound to a name at a time. A
single function may return multiple different types if it wishes
> I have tried this with constructors and failed,
> So I suppose I might need to compile the code or something like
> that to gain this feature if it exists.
Won't help. Python is a simple language, with little implicit magic.
There is no support for what you are describing in the language, no
matter how you compile it.
> I know it allows default values to function arguments but that is
> not sufficient for my purpose.
You're approaching Python with a C++/Java mindset. Don't do that. If
you try Python seriously, you'll find that you don't really need these
If you absolutely must have these features, stick to C++ or Java.
-- David Goodger
More information about the Python-list