Advertisements
Advertisements
प्रश्न
Write the overloaded function definitions of add()- on adds two numbers and other concatenates two strings.
कोड लेखन
Advertisements
उत्तर
Python cannot define two separate overloaded functions with the same name. However, the same add() function can perform both operations because + is polymorphic.
def add(a, b):
return a + b # Adds numbers or concatenates strings
print(add(10, 20))
print(add("Hello ", "World"))
30
Hello World
Here, add() is a single function; it is not traditional function overloading in Python.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
