Two functions with the same name
QuizMediumPython onlyAsked in: Accenture, Capgemini, Infosys, TCS, Wipro
Overloading means several functions with one name but different parameters (Java allows it). What happens when this runs in Python?
def greet(name):
return "hi " + name
def greet(name, greeting):
return greeting + " " + name
print(greet("Asha"))- TypeError: greet() missing 1 required positional argument: 'greeting'
- It prints "hi Asha"
- SyntaxError: duplicate function
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.