polymorphism in python by R4R Team

polymorphism in python-
The word polymorphism means having many forms. In programming, polymorphism means same function name (but different signatures) being uses for different types.

Example of inbuild polymorphism-
sum(1,2,3,4) will give 10
sum([1,2,3]) willl give 6

-Here sum() is a function which supports polymorphism beacause it add all argument which we pass, it also supports list, tuple,or individual elements to add.

User defined polymorphism-
program-

def add(x,y,z=0):
return x+y+z

print(add(2,3))
print(add(1,2,3))


output-

5
6


-In this program, we create a function which are able to add two number as well as three number.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!