Featured Article

Master the 3 Types of Arguments in Python: A Complete Guide

Nicole Jul 13, 2026

In the realm of Python programming, arguments play a pivotal role in functiondefinition and method invocation. They allow for flexibility and customization in code execution. At its core, an argument is a value provided during a function call that alters the behavior of the function accordingly. Python supports three types of arguments: positional, keyword, and default arguments. Let's delve into each, exploring their roles and usage.

Functions Arguments in Python: How to Use Them
Functions Arguments in Python: How to Use Them

Positional arguments occupy the placeholders in a function signature, defined in a specific order. They are accessed within the function body using an index, which facilitates ordered access to all provided arguments.

Types of Function Arguments in Python
Types of Function Arguments in Python

Positional Arguments

Positional arguments are crucial as they ensure that the correct values reach the intended function parameters. They are identified by their position, starting from zero. For instance, consider the following function definition:

Advanced of Arguments & Self in Python
Advanced of Arguments & Self in Python

```python def greet(name, age): print(f"Hello, {name}! You are {age} years old.") ```

Here, 'name' and 'age' are positional arguments. The function call, `greet("Alice", 30)`, supplies these arguments in the specified order: 'Alice' for 'name' and '30' for 'age'.

In a function call, positional arguments must be supplied in the order they are defined in the function signature. If omitted, a TypeError will be raised, highlighting the missing argument's position.

ARGS & KWARGS in Python
ARGS & KWARGS in Python

Required Arguments

Required positional arguments are mandatory and must always be provided during function calls. They are identified by their absence of any default value in the function definition. Failure to include them always leads to an error during runtime.

For example, in the `greet` function, 'name' and 'age' are required arguments. A call like `greet(30)` without providing a name will result in a TypeError.

Python Parameters vs Arguments Explained
Python Parameters vs Arguments Explained

Optional Arguments

Optional positional arguments, on the other hand, have a default value defined in the function signature. The default value is used when no explicit value is supplied during the function call. However, if an explicit value is provided, it replaces the default value.

Consider the following function:

Python Unit 3 Cheat Sheet 🐍 | Functions, Arguments, Lambda & Modules (AKTU)
Python Unit 3 Cheat Sheet 🐍 | Functions, Arguments, Lambda & Modules (AKTU)

```python def greet(name="Guest", age=0): print(f"Hello, {name}! You are {age} years old.") ```

Here, both arguments have default values. The function call, `greet()`, uses these defaults. However, a call like `greet("Bob")` will provide an explicit value for 'name', using its default age instead.

Keyword Arguments

an image of what are arg's and kwars in python?
an image of what are arg's and kwars in python?
a table that has some type of programming program written on it, with the words python and
a table that has some type of programming program written on it, with the words python and
Python VS R Language
Python VS R Language
Python Default Arguments Explained
Python Default Arguments Explained
a blue background with the words in it
a blue background with the words in it
a poster showing the different types of people
a poster showing the different types of people
All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)
Python important methods - Programming
Python important methods - Programming
Master Function Arguments in Python 🐍
Master Function Arguments in Python 🐍
Python vs Javascript
Python vs Javascript
What is Python iter Function How to Use it With Examples
What is Python iter Function How to Use it With Examples
Python Functions Cheat Sheet
Python Functions Cheat Sheet
Coding For Beginners Python - Learn the Basics - Functions
Coding For Beginners Python - Learn the Basics - Functions
Python args, kwargs, and All Other Ways to Pass Arguments to Your Function | Towards Data Science
Python args, kwargs, and All Other Ways to Pass Arguments to Your Function | Towards Data Science
Master Python Functions – Write Smarter Code! 🐍✨
Master Python Functions – Write Smarter Code! 🐍✨
a screenshot of a computer screen with the text looping through dictionaries in python
a screenshot of a computer screen with the text looping through dictionaries in python
Python Try and Except | Finally | Else | Raise Statements ⋆ IpCisco
Python Try and Except | Finally | Else | Raise Statements ⋆ IpCisco
API Error Handling in Python: Complete Guide with Code Examples
API Error Handling in Python: Complete Guide with Code Examples
two screens showing different types of text on the same screen, one with an error
two screens showing different types of text on the same screen, one with an error
Python Errors — Types, Causes, Examples & Explanation
Python Errors — Types, Causes, Examples & Explanation

Keyword arguments offer another way to supply values to function parameters, providing more flexibility. They are identified by a name-value pair, allowing functions to accept arguments in any order. This separation of names from values enables better readability and understanding of the code.

Extending the previous example, here's how you can use keyword arguments in Python:

```python def greet(name="Guest", age=0): print(f"Hello, {name}! You are {age} years old.") greet(name="Charlie", age=25) ```

In this function call, 'name' and 'age' are keyword arguments. The function call, `greet(name="Charlie", age=25)`, explicitly associates each argument with the correct parameter, regardless of the order they are defined in the function signature.

Named Keyword Arguments

Named keyword arguments, or 'kwargs, allow functions to accept an arbitrary number of arguments. They are defined using double asterisks ( ** ) in the function signature. The **kwargs parameter collects all remaining keyword arguments into a dictionary, providing a flexible way to accept additional parameters.

The following function accepts 'name' and 'age' as regular positional or keyword arguments, and anything else as named keyword arguments:

```python def greet(name="Guest", age=0, **kwargs): print(f"Hello, {name}! You are {age} years old. Other information: {kwargs}") greet("Daisy", 35, personality="cheerful", hobbies=["reading", "gardening"]) ```

The dictionary **kwargs collects all additional arguments not belonging to the regular parameters: 'name' and 'age'. In this case, it collects 'personality' and 'hobbies'.

Default Arguments

Default arguments provide a default value for a function parameter. If a value is not explicitly supplied during the function call, the function uses the default value defined during function definition.

Non-Defaulted Default Arguments

For the 'greet' function, 'name' and 'age' are both default positional arguments. The function call, `greet()`, uses these defaults. However, if we provide values during the function call, they replace the defaults, i.e., `greet("Eve", 32)`.

Defaulted Keyword Arguments

Defaulted keyword arguments work similarly. They are identified by a name-value pair, but their default value is used if no explicit value is provided during the function call. Once again, a provided value overrides the default, e.g., `greet(age=28)`.

Python's argument types offer versatility and robustness in function definition and invocation. They empower programmers to write more efficient, flexible, and readable code. Mastering these argument types is crucial for any Python developer. Have you found the perfect argument type for your next function? Dive deeper into Python's argument world to find the best fit for your needs!