Yes. You can use *args as a non-keyword argument. You will then be able to pass any number of arguments.

def manyArgs(*arg):
  print "I was called with", len(arg), "arguments:", arg

>>> manyArgs(1)
I was called with 1 arguments: (1,)
>>> manyArgs(1, 2, 3)
I was called with 3 arguments: (1, 2, 3)

As you can see, Python will unpack the arguments as a single tuple with all the arguments.

For keyword arguments you need to accept those as a separate actual argument, as shown in Skurmedel's answer.

Answer from unwind on Stack Overflow
🌐
Python Morsels
pythonmorsels.com › accepting-any-number-arguments-function
Accepting any number of arguments to a function - Python Morsels
November 18, 2020 - To make a function that accepts any number of arguments, you can use the * operator and then some variable name when defining your function's arguments. This lets Python know that when that function is called with any positional arguments, they ...
Discussions

How to pass a variable number of arguments to a function/method inside a method when calling a method, without having to define every single possible argument to be used?
Is this what you want? from pprint import pprint as pretty class A: def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) x = A(a=123, b=456) y = A(friends=["Alice", "Brandon", "Carly"], enemies=None) z = A() print(f"x has {x.a=}, {x.b=}") print(f"y has {y.friends=}, {y.enemies=}") print(f"z has {pretty(dir(z))}") ...if so, I'd recommend against it. You're begging for a troubleshooting nightmare trying to figure out what instances have what attributes. Better that you pre-define all the attributes you'll need, setting them to None. More on reddit.com
🌐 r/learnpython
8
0
July 31, 2022
Best way to make a function that requires many arguments
Why not represent the device with its own class? (Sounds like a good use case for a dataclass.) If you need that many parameters I would consider making them keyword-only so that you can't set the wrong parameter by accident. More on reddit.com
🌐 r/learnpython
42
40
July 1, 2024
python - Specifying an unlimited number of arguments to a commanline option - Stack Overflow
In Python, is there a way to specify an unlimited number of arguments to a command line option ? For example something like python myscript.py --use-files a b c d e. Note that I strictly want to us... More on stackoverflow.com
🌐 stackoverflow.com
python - How do I take unlimited sys.argv[] arguments? - Stack Overflow
To elaborate, I am interested in learning how to code out in python a sys.argv[] function that allows the user to supply as many arguments as the user wants. I am unsure on if there is a better way... More on stackoverflow.com
🌐 stackoverflow.com
🌐
UC Berkeley Statistics
stat.berkeley.edu › ~spector › extension › python › notes › node67.html
Variable Number of Arguments
A similar technique can be used to create functions which can deal with an unlimited number of keyword/argument pairs. If an argument to a function is preceded by two asterisks, then inside the function, Python will collect all keyword/argument pairs which were not explicitly declared as arguments ...
🌐
YouTube
youtube.com › shorts › TaW-9d2N1MQ
Python Functions: Mastering Unlimited Parameters with *args in Just 1 Minute! - YouTube
Are you tired of writing functions with a fixed number of parameters? Do you want to write more flexible and scalable code? In this video, we'll show you how...
Published   May 12, 2023
🌐
YouTube
youtube.com › code bear
Python Trick : Pass unlimited arguments to a function #python #pythonshorts #pythonforbeginners - YouTube
In this video ill show you a trick in python to pass unlimited parameters in a function #pythonprogramming #pythontutorial #python3
Published   December 2, 2022
Views   669
🌐
CodingNomads
codingnomads.com › python-decorators-passing-unlimited-arguments
Python Decorators Passing Unlimited Arguments
Then, in the function call ... got a whole chunk more general. You can do the same using Python's **kwargs to pass an unlimited number of named keyword arguments....
Find elsewhere
🌐
Quora
quora.com › Python-programming-language-How-do-I-define-a-function-in-Python-with-an-unlimited-number-of-arguments
Python (programming language): How do I define a function in Python with an unlimited number of arguments? - Quora
Answer (1 of 2): I'm going to give some background information first before actually answering your question. There's a good reason for this: I could just say *what* works, but you wouldn't really understand, whereas if I give you the background, you will learn a lot about *how* it works and you'...
🌐
Note.nkmk.me
note.nkmk.me › home › python
*args and **kwargs in Python (Variable-Length Arguments) | note.nkmk.me
May 12, 2025 - In Python, you can define functions that accept a variable number of arguments by prefixing parameter names with * or ** in the function definition. By convention, *args (arguments) and **kwargs (keyw ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › args-kwargs-python
*args and **kwargs in Python - GeeksforGeeks
In Python, *args and **kwargs are used to allow functions to accept an arbitrary number of arguments.
Published   September 20, 2025
🌐
Linuxtopia
linuxtopia.org › online_books › programming_books › python_programming › python_ch15s09.html
Python - Advanced Parameter Handling For Functions
In the section called “More Features” we hinted that Python functions can handle a variable number of argument values in addition to supporting optional argument values. Earlier, when we defined a function that had optional parameters, it had a definite number of parameters, but some (or ...
🌐
Reddit
reddit.com › r/learnpython › how to pass a variable number of arguments to a function/method inside a method when calling a method, without having to define every single possible argument to be used?
r/learnpython on Reddit: How to pass a variable number of arguments to a function/method inside a method when calling a method, without having to define every single possible argument to be used?
July 31, 2022 -

Howdy!

Say I have the following class scheme and example code. I can call a.Run_Model() and pass arguments to it, but I want some of those arguments to be passed to GridSearchCV inside a.Run_Model()

Class Test:

    def __init__(self):
        self.model = LinearRegression()

    def Run_Model(self, opt=False):
        if opt:
            self.model = GridSearchCV(self.model)

a = Test()
# I may want to change the model
a.model = GradientBoostingRegressor(max_depth=4)
a.Run_Model()

# how can I run this without having 
# to declare the cv variable on GridSearchCV inside Run_Method()?
a.Run_Model(opt=True, GSV_args={'cv':5})

I know I can do it by declaring the arguments as def Run_Model(self, cv=5) and subsequently pass them as GridSearchCV(self.model,cv=cv).

But this does not sound too flexible. I'd have to declare ALL GSC variables on two different spots just to pass some variables to the function inside the class. And I'd have to set all of them to some default value just so that nothing breaks if I decide to omit something at any time, or if I end up not wanting to use that particular part of the code.

Is there a way to pass a **kwargs to Run_Model() and have those same **kwargs be applied to GSC inside it without having to define every single possible GSC input?

This is an example as I could declare a.model = GSV outside the class and code to make it work, but I'm just looking for a better and more flexible way to pass arguments around to functions inside methods when calling methods.

I imagine I should pass around the bare minimum of variables this way, but there must be a way to do it that I'm not familiar with. So what can I do? Is it possible to do what I want to do?

Cheers!

🌐
PyXLL
pyxll.com › docs › userguide › udfs › varargs.html
Variable and Keyword Arguments - PyXLL User Guide
For practical purposes the limit is high enough that it is unlikely to be a problem. The absolute limit for the number of arguments is 255, however the actual limit for a function may be very slightly lower [1]. ... Python functions can take an arbitrary number of named arguments using the ...
🌐
Reddit
reddit.com › r/learnpython › best way to make a function that requires many arguments
r/learnpython on Reddit: Best way to make a function that requires many arguments
July 1, 2024 -

I have a function that requires many (~20) arguments, and I'm wondering if there's a better way... For context, I am using gdsfactory to make mask layouts for fabricating semiconductor devices. My function creates the device and returns it as a gdsfactory component object which can be written to a .gds CAD file. The arguments specify all the possible device parameters for fabrication (dimensions, spacing between metal connections, etc. etc.), and the function looks something like this:

def my_device(arg1=default_val1, arg2=default_val2, arg3=default_val3,... argN=default_valN):
# code to create the device layout using all the arguments
return component

In most use cases the default values are fine so I can call the function without specifying arguments, but I still need to have the option to specify any of the device parameters if I want to. I know it's generally considered bad practice to have so many arguments, so I'm curious if there's a better way to accomplish this while still being able to create my component with one function call?

🌐
YouTube
youtube.com › watch
Accepting any number of arguments to a function in Python - YouTube
To make a function that accepts any number of arguments, you can use the * operator and then some variable name when defining your function. Some of Python's...
Published   January 9, 2023
🌐
Educative
educative.io › answers › what-are-the-variable-number-of-arguments-in-python
What are the variable number of arguments in Python?
Line 5: When calling key_args with ... last) are captured by **kwargs. In Python, *args and **kwargs are used in function definitions to handle a variable number of arguments flexibly....
🌐
Medium
medium.com › data-science › how-to-use-variable-number-of-arguments-in-python-functions-d3a49a9b7db6
How To Use A Variable Number of Arguments in Python Functions | by Ahmed Besbes | TDS Archive | Medium
January 22, 2022 - In this article, we’ll learn about *args and **kwargs, two special Python symbols that you may have probably encountered in some function signatures before. What do they do? What problems do they solve?
🌐
Scaler
scaler.com › home › topics › variable length argument in python
Variable Length Argument in Python - Scaler Topics
June 22, 2024 - These methods can take an undetermined quantity of data in consecutive entries or named parameters. Variable-length arguments, abbreviated as varargs, are defined as arguments that can also accept an unlimited amount of data as input.