PRO
Timi
asked

Expert
Abhay Jajodia answered
Hi Timi,
Good question. It depends on how the function is defined.
Here’s your example:
def greet(message):
print(message)
greet('Hi', 'Hello')
In this case, the function greet is defined to accept only one argument — message. But when you call it with two arguments ('Hi', 'Hello'), Python throws an error:
TypeError: greet() takes 1 positional argument but 2 were given
So actually, it doesn’t return one output — it raises an error because you passed more arguments than expected.
If you want the function to handle multiple messages, you can use *args, like this:
def greet(*messages):
for message in messages:
print(message)
greet('Hi', 'Hello')
Output:
Hi
Hello
Using *messages lets the function accept any number of arguments and print each one.
If you have more questions, I am here to help.
Python
This question was asked as part of the Learn Python Intermediate course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer