Python: Positional vs Keyword Arguments - A Comprehensive Comparison

Benjamin Jul 11, 2026

In the realm of Python programming, arguments passed to functions can be categorized into two primary types: positional arguments and keyword arguments. Understanding the distinction between these two is crucial for writing clean, efficient, and maintainable code. Let's delve into the details of each, their differences, and when to use them.

Python Functions With Multiple Inputs | Positional & Keyword Arguments
Python Functions With Multiple Inputs | Positional & Keyword Arguments

Positional arguments are those that are passed to a function based on their position, starting from the left. They are required and must be provided in the correct order. On the other hand, keyword arguments are passed using their names, allowing for more flexibility and optional inclusion. Let's explore these concepts further.

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

Positional Arguments

Positional arguments are the most basic type of arguments in Python. They are passed to a function in the order they are defined. Each positional argument must be provided when calling the function, and they are matched up with the function's parameters based on their position.

Master Function Arguments in Python 🐍
Master Function Arguments in Python 🐍

Consider the following example function with two positional arguments:

def greet(first_name, last_name):
    print(f"Hello, {first_name} {last_name}!")

To call this function, you must provide both arguments in the correct order:

Library vs Module vs Package in Python: Differences and Examples
Library vs Module vs Package in Python: Differences and Examples

greet("John", "Doe")

Attempting to swap the arguments or omit one will result in a TypeError.

Requirements and Order

Positional arguments are required and must be provided in the correct order. This can make functions with many positional arguments difficult to use, as it's easy to forget the order or accidentally swap arguments.

the problem with fixed arguments is that you can't fix them
the problem with fixed arguments is that you can't fix them

To mitigate this, Python allows you to use the `/` symbol to separate required positional arguments from optional keyword arguments. This is known as a function's signature. Here's an example:

def greet(first_name, last_name, /, greeting="Hello"):
    print(f"{greeting}, {first_name} {last_name}!")

In this case, `first_name` and `last_name` are required positional arguments, while `greeting` is an optional keyword argument with a default value of "Hello".

Variable-length Positional Arguments

Python VS R Language
Python VS R Language

Python also supports variable-length positional arguments using the `*args` syntax. This allows a function to accept any number of positional arguments, which are then stored as a tuple. Here's an example:

def add(*args):
    return sum(args)

You can call this function with any number of arguments, like so:

an image of what are arg's and kwars in python?
an image of what are arg's and kwars in python?
Python vs Java vs C | Complete Visual Comparison for Beginners (2026 Guide)
Python vs Java vs C | Complete Visual Comparison for Beginners (2026 Guide)
Functions Arguments in Python: How to Use Them
Functions Arguments in Python: How to Use Them
Python Positional-Only Arguments (Complete Guide for Beginners)
Python Positional-Only Arguments (Complete Guide for Beginners)
a computer screen showing the different types of commands and symbols for each type of device
a computer screen showing the different types of commands and symbols for each type of device
Python Default Arguments Explained
Python Default Arguments Explained
Python Keyword Arguments (Complete Guide for Beginners)
Python Keyword Arguments (Complete Guide for Beginners)
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 Conditional Statements & Loops
Python Conditional Statements & Loops
💜 List vs Tuple in Python 🐍 Confused between Lists and Tuples?
💜 List vs Tuple in Python 🐍 Confused between Lists and Tuples?
a blue background with the words in it
a blue background with the words in it
Master Python Functions – Write Smarter Code! 🐍✨
Master Python Functions – Write Smarter Code! 🐍✨
TUPLES vs LISTS
TUPLES vs LISTS
append() vs extend() in Python (Most Beginners Get Confused)
append() vs extend() in Python (Most Beginners Get Confused)
a poster with different types of text on it
a poster with different types of text on it
Mastering Essential Python Methods: A Comprehensive Guide 🐍
Mastering Essential Python Methods: A Comprehensive Guide 🐍
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
a black background with text that reads master flexible python functions learn how to write functions that accept a variable number of arguments
a black background with text that reads master flexible python functions learn how to write functions that accept a variable number of arguments
a table with words that are used to describe the keywords for each keyword
a table with words that are used to describe the keywords for each keyword
a black background with white text that says adding numbers with args python def add numbers tags for
a black background with white text that says adding numbers with args python def add numbers tags for

print(add(1, 2, 3, 4, 5))  # Output: 15

Keyword Arguments

Keyword arguments, on the other hand, are passed to a function using their names, allowing for more flexibility and optional inclusion. They are not dependent on position and can be provided in any order. Keyword arguments are always preceded by an equals sign (=) followed by their value.

Let's revisit the previous `greet` function and add a keyword argument for the greeting:

def greet(first_name, last_name, greeting="Hello"):
    print(f"{greeting}, {first_name} {last_name}!")

Now, you can call this function using the keyword argument `greeting`, like so:

greet("John", "Doe", greeting="Howdy")

In this case, the greeting "Howdy" is passed using its name, allowing for more flexibility in function calls.

Requirements and Order

Keyword arguments are optional and can be provided in any order. This makes functions with many arguments easier to use, as you can simply provide the arguments you need in any order.

However, it's important to note that keyword arguments must come after any required positional arguments. If you try to provide a keyword argument before a positional argument, you'll encounter a SyntaxError.

Variable-length Keyword Arguments

Python also supports variable-length keyword arguments using the `**kwargs` syntax. This allows a function to accept any number of keyword arguments, which are then stored as a dictionary. Here's an example:

def greet(**kwargs):
    if "first_name" in kwargs and "last_name" in kwargs:
        print(f"Hello, {kwargs['first_name']} {kwargs['last_name']}!")
    else:
        print("Invalid arguments")

You can call this function with any number of keyword arguments, like so:

greet(first_name="John", last_name="Doe", greeting="Howdy")

In conclusion, understanding the difference between positional and keyword arguments in Python is essential for writing clean, efficient, and maintainable code. Positional arguments are required and must be provided in the correct order, while keyword arguments offer more flexibility and can be provided in any order. By mastering these concepts, you'll be well on your way to becoming a proficient Python programmer. Happy coding!