Timi Fayomi
PRO
last year
Timicountry asked

Can you please explain why it returns only one output?

Abhay Jajodia
Expert
last year
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 argumentmessage. 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.