Parameters can be required or optional depending on how they appear in the function definition:

def myfunction(p1, p2, p3=False, p4=5)

In this definition, parameters p1 and p2 are required. p3 is optional and will acquire the value False if not provided by the caller. p4 is also optional and will acquire the value 5 if not provided.

If you really need to pass ten or more parameters into a function, it might be better to pass them as a dictionary:

args = {'a': something, 'b': something_else, 'c': 5, 'd': 99.99, ... }
myfunc(args)
Answer from John Gordon on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › article › required-arguments-in-python
Required arguments in Python
March 25, 2026 - Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition.
🌐
Alma Better
almabetter.com › bytes › tutorials › python › arguments-in-python-functions
Arguments in Python Functions
April 19, 2024 - Default arguments in Python have pre-set values if the user does not specify them when calling the function. The default value can be any data type like a list, dictionary, string, number, etc.Default arguments are defined by assigning values ...
Discussions

python - Argparse: Required arguments listed under "optional arguments"? - Stack Overflow
I use the following simple code ... them is required. Unfortunately, when the user runs the script without providing the argument, the displayed usage/help text does not indicate that there is a non-optional argument, which I find very confusing. How can I get python to indicate ... More on stackoverflow.com
🌐 stackoverflow.com
Argparse - Optional in conditional
Subreddit for posting questions and asking for general advice about all topics related to learning python. ... I know that one can set options that are compulsory in argparse by using the required flag. More on reddit.com
🌐 r/learnpython
6
4
April 26, 2020
Missing required positional argument in class?
Your definition of getLetter(): def getLetter(self, index): return self.__letter[index] When you call getLetter(): ltr1.getLetter() You defined getLetter() to expect an argument referred to as index, but you didn't provide it when you called the function. Presumably when you call getLetter() it should look more something like ltr1.getLetter(2). More on reddit.com
🌐 r/learnpython
3
2
March 8, 2018
I'm getting this error even though the arguments are in "__init__() missing 3 required positional arguments: 'make', 'model', and 'year'

The error is because the arguments are missing in line 24. It should be:

C = Car("Toyota", "Corolla", "2005")

C.get_make()
C.get_model()
C.get_year()
More on reddit.com
🌐 r/learnpython
12
2
November 7, 2016
🌐
Python
docs.python.org › 3 › library › argparse.html
argparse — Parser for command-line options, arguments and subcommands
Each parameter has its own more detailed description below, but in short they are: name or flags - Either a name or a list of option strings, e.g. 'foo' or '-f', '--foo'. action - The basic type of action to be taken when this argument is encountered at the command line. nargs - The number of command-line arguments that should be consumed. const - A constant value required by some action and nargs selections.
🌐
EyeHunts
tutorial.eyehunts.com › home › required arguments in python
Required Arguments in Python
July 13, 2023 - Here’s an example of a Python function with required arguments: def calculate_rectangle_area(length, width): area = length * width print(f"The area of the rectangle is: {area}") calculate_rectangle_area(5, 3) calculate_rectangle_area(5) ... If you omit either the length or width argument or provide them in the wrong order, you will encounter an error.
🌐
Real Python
realpython.com › python-optional-arguments
Using Python Optional Arguments When Defining Functions – Real Python
July 19, 2026 - Parameters are names in a function definition, while arguments are the values you pass when calling the function · 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
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › what-are-required-arguments-of-a-function-in-python
What are required arguments of a function in python?
September 16, 2022 - Functions accept arguments that can contain data. The function name is followed by parenthesis that list the arguments. Simply separate each argument with a comma to add as many as you like. As the name implies, mandatory arguments are those that mus
🌐
Medium
medium.com › @khanfarazahmed7 › difference-between-required-optional-positional-and-keyword-arguments-in-python-functions-1fa9cd6a46c4
Difference between Required, Optional, Positional and Keyword arguments in Python functions | by Faraz Khan | Medium
November 15, 2023 - Optional: Required arguments must always be provided during the function call. Optional arguments, however, are gracious — they can be omitted. Order of Arrival: All non-keyword arguments must precede the keyword arguments in the function call.
🌐
Aimtocode
aimtocode.com › python-required-argument.php
Required Arguments In Python With Example-Aimtocode
Also functions are a key way to define interfaces so programmers can share their code. Required arguments are the arguments passed to a function in correct positional order.
🌐
Educative
educative.io › answers › what-is-argparse-required-in-python
What is argparse required in Python?
It displays the generic usage of the program, help, and errors. required is a parameter of the ArugmentParser object’s function add_argument(). By default, the arguments of type -f or --foo are optional and can be omitted.
🌐
PyTutorial
pytutorial.com › handling-typeerror-in-python-required-argument-missing
PyTutorial | Handling TypeError in Python: Required Argument Missing
3 weeks ago - Positional arguments: Passed in order. Keyword arguments: Passed using the parameter name. Default arguments: Have a default value if not provided. If a function expects a parameter and it is not provided during the call, Python raises a TypeError. def greet(name): # This function requires a 'name' parameter return f"Hello, {name}!" # Calling the function without the required argument message = greet() print(message)
🌐
Learn Python
learnpython.dev › 02-introduction-to-python › 060-functions › 30-function-arguments
Function Arguments :: Learn Python by Nina Zakharenko
Arguments in Practice Positional arguments are required Positional arguments are all required, and must be given in the order they are declared. For example, this function doesn’t do what we expected, because we passed in our arguments in the wrong order. In the REPL: >>> def say_greeting(name, ...
🌐
Scaler
scaler.com › home › topics › python › python function arguments
Python Function Arguments with Types and Examples - Scaler Topics
November 21, 2023 - Whenever you declare a function, the non-default arguments are specified before the default arguments. The default arguments are specified at the end, meaning any arguments specified to the right of a default argument must also be a default one. It is to prevent any ambiguity by the Python ...
Top answer
1 of 7
505

Parameters starting with - or -- are usually considered optional. All other parameters are positional parameters and as such required by design (like positional function arguments). It is possible to require optional arguments, but this is a bit against their design. Since they are still part of the non-positional arguments, they will still be listed under the confusing header “optional arguments” even if they are required. The missing square brackets in the usage part however show that they are indeed required.

See also the documentation:

In general, the argparse module assumes that flags like -f and --bar indicate optional arguments, which can always be omitted at the command line.

Note: Required options are generally considered bad form because users expect options to be optional, and thus they should be avoided when possible.

That being said, the headers “positional arguments” and “optional arguments” in the help are generated by two argument groups in which the arguments are automatically separated into. Now, you could “hack into it” and change the name of the optional ones, but a far more elegant solution would be to create another group for “required named arguments” (or whatever you want to call them):

parser = argparse.ArgumentParser(description='Foo')
parser.add_argument('-o', '--output', help='Output file name', default='stdout')
requiredNamed = parser.add_argument_group('required named arguments')
requiredNamed.add_argument('-i', '--input', help='Input file name', required=True)
parser.parse_args(['-h'])
usage: [-h] [-o OUTPUT] -i INPUT

Foo

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Output file name

required named arguments:
  -i INPUT, --input INPUT
                        Input file name
2 of 7
138

Since I prefer to list required arguments before optional, I hack around it via:

parser = argparse.ArgumentParser()
parser._action_groups.pop()
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
required.add_argument('--required_arg', required=True)
optional.add_argument('--optional_arg')
return parser.parse_args()

and this outputs:

usage: main.py [-h] --required_arg REQUIRED_ARG [--optional_arg OPTIONAL_ARG]

required arguments:
  --required_arg REQUIRED_ARG

optional arguments:
  --optional_arg OPTIONAL_ARG

I can live without -h, --help showing up in the optional arguments group.

🌐
WsCube Tech
wscubetech.com › resources › python › function-argument
Function Arguments in Python: All Types With Examples
August 6, 2026 - Learn Python function arguments with easy examples. Explore the types of function arguments in Python, how to pass arguments & test your knowledge with a quiz.
🌐
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 - Required arguments are often called “required positional arguments” because they must be assigned at a particular position in a function call. If you specify an optional argument before a required argument, Python returns an error that looks like this:
🌐
w3tutorials
w3tutorials.net › blog › run-python-script-with-some-of-the-argument-that-are-optional
How to Run a Python Script with Required and Optional Arguments: A Step-by-Step Guide — w3tutorials.net
To make these scripts flexible and user-friendly, they need to accept input from the command line. This input typically comes in two forms: required arguments (mandatory for the script to run) and optional arguments (additional settings that ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-functions
Python Functions - GeeksforGeeks
Non-Keyword Arguments (*args): Hey Welcome Keyword Arguments (**kwargs): first == Geeks mid == for last == Geeks ... A function defined inside another function is called an inner function (or nested function).
Published: 2 weeks ago