If you assign them in the call of the function you can pre-empt which parameter you are passing in.

def foo( a, b=None, c=None):
    print("{},{},{}".format(a,b,c))

>>> foo(4) 
4,None,None
>>> foo(4,c=5)
4,None,5
Answer from corn3lius on Stack Overflow
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › master python optional arguments usage [tutorial]
Master Python Optional Arguments Usage [Tutorial] | GoLinuxCloud
January 9, 2024 - Argument unpacking allows you to pass multiple arguments to a function by unpacking a list or tuple using * or a dictionary using **. For instance, if you have a list args = [1, 2, 3] and a function def sum(a, b, c), you can call sum(*args) ...
Discussions

Choose multiple optional arguments with argparse in Python 3 - Stack Overflow
Exit..") else: print ("\nNo Arguments passed. Set or Use a default value...\n") The result is that, if only -o is specified, the script exits (as expected), however, if -n is added, the first condition is True. $ python test.py -o output.txt --number not specified. More on stackoverflow.com
🌐 stackoverflow.com
design patterns - Python function with many optional arguments - Stack Overflow
P.S. I have considered making a ... most of the time only one or two optional arguments are used. EDIT1: I don't want to use kwargs as I want names of arguments and default values visible in my IDE (PyCharm) ... @vash_the_stampede In python if you have a list as a default for ... More on stackoverflow.com
🌐 stackoverflow.com
September 24, 2018
python - Call function with multiple optional arguments of different types - Stack Overflow
I have already checked this post and this post, but couldn't find a good way of sorting the problem of my code out. I have a code as follows: class foo: def __init__(self, foo_list, str1, str2)... More on stackoverflow.com
🌐 stackoverflow.com
How to set several required arguments into an optional group?
Hello: I’m trying to use the argparse module to provide the argument parsing. In my use case, I have eight positional arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: arg1 and arg2 are required. arg3 and arg4 are a couple and optional. But if users pass in one(arg3 or arg4), they ... More on discuss.python.org
🌐 discuss.python.org
6
0
May 27, 2022
🌐
Real Python
realpython.com › python-optional-arguments
Using Python Optional Arguments When Defining Functions – Real Python
October 27, 2025 - You can assign default values to parameters so that arguments become optional · You should avoid mutable data types like lists or dictionaries as default values to prevent unexpected behavior · You can use *args to collect any number of positional arguments and **kwargs to collect keyword arguments · Python raises TypeError when you omit required arguments and SyntaxError when you misorder parameters with defaults
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-pass-optional-parameters-to-a-function-in-python
How to Pass Optional Parameters to a Function in Python - GeeksforGeeks
April 2, 2025 - In Python, functions can have optional parameters by assigning default values to some arguments. This allows users to call the function with or without those parameters, making the function more flexible.
🌐
Squash
squash.io › how-to-define-a-function-with-optional-arguments-in-python
How to Define a Function with Optional Arguments in Python
November 2, 2023 - If the name argument is not provided, the function will use the default value and greet the person as "stranger". You can also define a function with multiple optional arguments by providing default values for each argument.
🌐
University of Toronto
teach.cs.toronto.edu › ~csc110y › fall › notes › 12-interlude-nifty-python-features › 03-functions-with-optional-parameters.html
12.3 Functions with Optional Parameters
However, we’ve seen a few different examples of built-in Python functions that seem to take in a varying number of arguments. Here’s an example with the round function: >>> round(3.46, 1) # round to 1 decimal place 3.5 >>> round(3.46) # round to the nearest integer 3 · Similarly, the list.pop method takes an index as an optional argument; if this argument is omitted, the last element in the list is removed and returned.
🌐
Delft Stack
delftstack.com › home › howto › python › python optional arguments optional parameters python
Optional Arguments in Python | Delft Stack
October 10, 2023 - If you don’t want to pass your Age to the above function as an argument, you can use something called an optional argument. You can make any number of arguments or parameters optional in Python.
Find elsewhere
🌐
Career Karma
careerkarma.com › blog › python › python optional arguments: a how-to guide
Python Optional Arguments: A How-To Guide | Career Karma
December 1, 2023 - The number of values we specify in a function call must be equal to the number of arguments that a function accepts. This is unless we use optional arguments. In which case, we can specify fewer arguments than a function accepts because some arguments are optional. A Python optional argument is an argument with a default value.
🌐
Stack Overflow
stackoverflow.com › questions › 46374703 › choose-multiple-optional-arguments-with-argparse-in-python-3
Choose multiple optional arguments with argparse in Python 3 - Stack Overflow
import argparse cli_argparser = argparse.ArgumentParser(description='') cli_argparser.add_argument('-n', '--number', type=int, help="Pass a number 'n' to script.", required=False) cli_argparser.add_argument('-q', '--query', help="Pass a query to the script", required=False) cli_argparser.add_argument('-o', '--outfile', help="Saves the output to an external file.", required=False) cli_args = cli_argparser.parse_args() if (cli_args.number): print ("\n--number has the value '" + str(cli_args.number) + "'\n") elif (cli_args.query): print ("\n--query has the value '" + cli_args.query + "'\n") elif (cli_args.outfile): print ("\n--output has the value '" + cli_args.outfile + "'\n") else: print ("\nNo Arguments passed.
🌐
Linux Manual Page
linux.die.net › diveintopython › html › power_of_introspection › optional_arguments.html
4.2. Using Optional and Named Arguments
Python allows function arguments to have default values; if the function is called without the argument, the argument gets its default value. Futhermore, arguments can be specified in any order by using named arguments. Stored procedures in SQL Server Transact/SQL can do this, so if you're a SQL Server scripting guru, you can skim this part. Here is an example of info, a function with two optional ...
🌐
The Hitchhiker's Guide to Python
python-docs.readthedocs.io › en › latest › writing › style.html
Code Style - The Hitchhiker's Guide to Python - Read the Docs
Here cc and bcc are optional, and evaluate to None when they are not passed another value. Calling a function with keyword arguments can be done in multiple ways in Python, for example it is possible to follow the order of arguments in the definition without explicitly naming the arguments, like in send('Hello', 'World', 'Cthulhu', 'God'), sending a blind carbon copy to God.
🌐
Earth Data Science
earthdatascience.org › home
Write Functions with Multiple Parameters in Python | Earth Data Science - Earth Lab
November 12, 2019 - def mean_mm_to_in_arr(arr_mm, axis_value=None): """Calculate mean values of input array and convert values from millimeters to inches. If an axis is specified, the mean will be calculated along that axis. Parameters ---------- arr_mm : numpy array Numeric values in millimeters. axis_value : int (optional) 0 to calculate mean for each column.
🌐
Programiz
programiz.com › python-programming › function-argument
Python Function Arguments (With Examples)
To handle this kind of situation, we can use arbitrary arguments in Python. Arbitrary arguments allow us to pass a varying number of values during a function call. We use an asterisk (*) before the parameter name to denote this kind of argument. For example, # program to find sum of multiple ...
🌐
Python.org
discuss.python.org › python help
How to set several required arguments into an optional group? - Python Help - Discussions on Python.org
May 27, 2022 - Hello: I’m trying to use the argparse module to provide the argument parsing. In my use case, I have eight positional arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: arg1 and arg2 are required. arg3 and arg4 are a couple and optional. But if users pass in one(arg3 or arg4), they ...
🌐
Delft Stack
delftstack.com › home › howto › python › python class optional arguments
Optional Arguments for a Class Constructor in Python | Delft Stack
October 10, 2023 - The class Point constructor accepts three arguments: x, y, and z. Here z is the optional argument because it has a default value set for it. This makes the other two arguments, x and y, compulsory. For Object 1, no value was passed for the z argument, and from the output, we can see that the default value was considered for z. And, for Object 3, 100 was passed for the z argument, and from the output, we can see that 100 was considered over the default 0 value. You can set multiple optional arguments by defining default values for them in the class constructor’s signature.
🌐
Python.org
discuss.python.org › python help
Multiple optional position args with argparse.ArgumentParser - Python Help - Discussions on Python.org
February 11, 2025 - Some Unix filters accept zero, one or two positional arguments to represent inputs and outputs. I have such a script which does this. The ArgumentParser bit looks like this: parser = argparse.ArgumentParser() parser.add_argument("infile", default=None, nargs="?") parser.add_argument("outfile", default=None, nargs="?") options, _args = parser.parse_known_args() This works as expected, but the help output doesn’t look quite right to me: % heictopnm -h usage: heictopnm [-h] [infi...
🌐
Reddit
reddit.com › r/discord_bots › multiple optional arguments (discord.py)
r/Discord_Bots on Reddit: Multiple Optional Arguments (discord.py)
May 13, 2021 -

Consider the following command:

>purge <option>="text" <count>=1 *<content>

  • i.e. >purge 10 swear_word

    • remove within the last 10 messages any message that contains "swear_word"

  • i.e. >purge text 10 swear_word

    • remove within the last 10 messages any message that contains "swear_word"

  • i.e >purge image 10

    • remove within the last 10 messages any message with an image

I'm still relatively new to Python's syntax. How would I define a function like this? My current issue is that when the count is provided without an <option> the default doesn't kick in leaving me with parameters that look like the following: <10><1><swear_word>