Can functions have multiple arguments?

QuestionsQuestions4 SkillsProDec, 22 2025
0195

Yes, absolutely! Functions can have as many arguments as you need. You simply separate them with commas inside the parentheses.

Example of Multiple Arguments

Let's say you want to greet someone and also tell them what day it is. You would define the function like this:

# Define a function with two arguments: name and day
def greet_user(name, day):
    print(f"Hello {name}, happy {day}!")

# Call the function with two values
greet_user("Carlos", "Monday")
greet_user("Wanda", "Friday")

Key things to remember:

  1. Order Matters: By default, Python matches the values you provide to the arguments in the order they appear. In the example above, "Carlos" goes to name and "Monday" goes to day.
  2. Matching Count: If you define a function with two arguments, you must provide exactly two values when you call it (otherwise, Python will show an error).

Try it yourself!

You can modify your arguments.py file to try this out:

  1. Change the function definition to: def say_hello(name, city):
  2. Change the print statement to: print(f'Hello {name} from {city}')
  3. Call it with two strings: say_hello('Carlos', 'New York')

Would you like to see how to handle a situation where you don't know how many arguments you'll need?

0 Comments

no data
Be the first to share your comment!