Get startedGet started for free

Adding arbitrary arguments

In the video, you saw that Python allows custom functions to accept any number of positional arguments through the use of "Arbitrary arguments". This flexibility enables functions to be used in a variety of ways while still producing the expected results!

Using this power, you'll build a function that concatenates (joins together) strings, regardless of how many blocks of text are provided!

This exercise is part of the course

Intermediate Python for Developers

View Course

Exercise instructions

  • Define a function called concat() that accepts arbitrary arguments called args.
  • Create a variable called result and assign an empty string to it.
  • Use a for loop to iterate over each arg in args.
  • Call the function to test that it works correctly.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define a function called concat
____
  
  # Create an empty string
  result = ____
  
  # Iterate over the Python args tuple
  ____:
    result += " " + arg
  return result

# Call the function
print(____("Python", "is", "great!"))
Edit and Run Code