How does polymorphism work in Python?
- by froadie
I'm new to Python... and coming from a mostly Java background, if that accounts for anything.
I'm trying to understand polymorphism in Python. Maybe the problem is that I'm expecting the concepts I already know to project into Python. But I put together the following test code:
class animal(object):
"empty animal class"
class dog(animal):
"empty dog class"
myDog = dog()
print myDog.__class__ is animal
print myDog.__class__ is dog
From the polymorphism I'm used to (e.g. java's instanceof), I would expect both of these statements to print true, as an instance of dog is an animal and also is a dog. But my output is:
False
True
What am I missing?