Skip to main content

Command Palette

Search for a command to run...

*args In Python

The Argument Tsunami

Published
3 min readView as Markdown
*args In Python
T
I document the weird thresholds of programming—turning confusion into clarity through annotated scrolls, beginner rituals, and product flows. From API-fetching to ergonomic selection, every scroll is a teachable moment. TheCodedHuman isn’t a title—it’s a mindset. A ritual alignment to the work we’re truly meant to do.

What is *args in layman terms ?

Imagine you’re the one in your family who goes out to buy groceries. Your mother gives you a list — sometimes 3 items, sometimes 10. You don’t say, “Mom, please stick to only 5 items.” (Don’t try if you’re alive💀).

You simply take whatever she gives and go buy it.

That’s exactly what *args does in Python.

It lets a function accept any number of inputs — just like your grocery list. Whether it’s 2 or 20 items, the function handles them all without complaint.


So, What is *args in professional terms ?

In Python, *args allows a function to accept a variable number of positional arguments. It collects all extra arguments passed to the function into a tuple, enabling flexible and dynamic function calls without requiring a fixed number of inputs.

This is especially useful when:

  • You don’t know in advance how many arguments a user might pass.

  • You want to build reusable, adaptable functions.

  • You’re designing APIs, decorators, or wrappers that need to forward arguments.

For Example

def log_events(*args):
    for event in args:
        print("Event:", event)

log_events("Login", "File Upload", "Logout")

Output

Event: Login
Event: File Upload
Event: Logout

Can’t I just take a list as an input rather than *args?

Yes, you can pass a list to a function — but the way you call the function and how it receives the data will be different.

  1. Using a list
def myFunction(items):
    print("User gave input: ", items)

myFunction(["item_1", "item_2", "item_3"]) 
# Here, the function gets one argument - a list.
  1. Using *args
def that_function(*items):
    print("User gave input: ", items)

that_function("item_1", "item_2", "item_3")
# Here, the function gets three separate arguments, collected into a tuple.

Output

User gave input: ('item_1', 'item_2', 'item_3')

Why Use *args Then

  • By using *args function to accept any number of arguments directly,

  • We can unpack a list and pass it into a*args function, as follows:

      my_list = ["item_1", "item_2", "item_3"]
      that_function(*my_list)
    
  • This gives you the best of both worlds — flexibility and clarity.


Didn’t *args made the traditional method deprecated ?

Not at all. Both have their place

Use Traditional Arguments When:

  • You want exactly 2 or 3 inputs.

  • You want to validate or enforce specific parameters.

  • You want clarity and simplicity for fixed tasks.

Use *args When:

  • You want to accept any number of inputs.

  • You’re building reusable, generic, or helper functions.

  • You don’t want to restrict the caller.

      def greet_all(*names):
          for name in names:
              print(f"Hello, {name}!")
    

Parameters In Python

Part 3 of 3

A series of annotated scrolls explaining Python’s parameters—from sandals to starstorms.

Start from the beginning

Parameters and Arguments

Expectation and Reality

More from this blog

Parameters In Python

3 posts

A ritual vault by TheCodedHuman—documenting weird thresholds, beginner insights, and legacy-grade clarity across Python, product choices, and silent strength.