args (arguments)

In Python, *args is a special syntax in function definitions that allows the function to accept an undetermined number of arguments. When you prefix an argument name with an asterisk (*), that argument collects positional arguments into a tuple.

This feature is particularly useful when you’re not sure how many arguments might be passed to a function. The name args is just a convention. In practice, you can use any valid identifier after the asterisk, and using descriptive names is always recommended.

Using *args makes your functions flexible and adaptable to different input sizes. It allows you to write functions that can handle a variety of input scenarios without needing to know in advance how many arguments a user will pass.

Example

Here’s an example of how you can use the *args syntax in a Python function:

Python
>>> def greet(*names):
...     for name in names:
...         print(f"Hello, {name}!")
...

>>> greet("Alice", "Bob", "Charlie")
Hello, Alice!
Hello, Bob!
Hello, Charlie!

In this example, the greet() function can take any number of people’s names, and it will greet each one.

Tutorial

Python args and kwargs: Demystified

In this step-by-step tutorial, you'll learn how to use args and kwargs in Python to add more flexibility to your functions. You'll also take a closer look at the single and double-asterisk unpacking operators, which you can use to unpack any iterable object in Python.

intermediate python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated July 4, 2025 • Reviewed by Martin Breuss
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy