How to use polymorphism with a function in Python

1 Answer

0 votes
class Dog(object):
    def info(self):
        print("legs, hair, walk")


class Fish(object):
    def info(self):
        print("gills, fins, swim")


def description(animalType):
    animalType.info()


d = Dog()
f = Fish()

description(d)
description(f)


'''
run:
 
legs, hair, walk
gills, fins, swim
 
'''

 



answered Jun 21, 2018 by avibootz

Related questions

1 answer 163 views
1 answer 188 views
1 answer 221 views
1 answer 200 views
1 answer 171 views
3 answers 370 views
...