Table of contents
1.
Introduction
2.
Positional Arguments
2.1.
Syntax
2.2.
Example of Positional Arguments
3.
Difference between Keyword and Positional Argument
3.1.
Using Positional Arguments
3.2.
Using Keyword Arguments
4.
Key Differences
5.
Frequently Asked Questions
5.1.
What happens if I pass arguments in the wrong order?
5.2.
Can I mix positional and keyword arguments?
5.3.
When should I use keyword arguments instead of positional arguments?
6.
Conclusion
Last Updated: Mar 11, 2025
Medium

Positional Argument in Python

Author Sinki Kumari
0 upvote

Introduction

In Python, positional arguments are arguments that are passed to a function in a specific order. The function assigns values to parameters based on their position in the function call. The order of these arguments matters, and incorrect placement can lead to unexpected results or errors. 

Positional Argument in Python

In this article, you will learn how positional arguments work, their syntax, and best practices for using them effectively in Python functions.

Positional Arguments

A positional argument is an argument that is passed to a function based on its position. When calling a function, values must be passed in the same order as the parameters are defined.

Syntax

# Defining a function with positional arguments

def greet(name, age):
    print(f"Hello, my name is {name} and I am {age} years old.")

# Calling the function with positional arguments
greet("Alice", 25)
You can also try this code with Online Python Compiler
Run Code

 

Output:

Hello, my name is Alice and I am 25 years old.

 

Explanation:

  • The function greet() takes two arguments: name and age.
     
  • We passed the values "Alice" and 25 in the same order as the function parameters.
     
  • If we change the order of arguments, the output will be different.
# Changing the order
greet(25, "Alice")
You can also try this code with Online Python Compiler
Run Code

 

Output:

Hello, my name is 25 and I am Alice years old.

 

Since name expects a string and age expects an integer, switching them leads to incorrect output.

Example of Positional Arguments

Let's consider another example where we define a function to calculate the area of a rectangle.

# Function to calculate the area of a rectangle
def area(length, width):
    return length * width

# Calling the function
result = area(10, 5)
print("Area of rectangle:", result)
You can also try this code with Online Python Compiler
Run Code

 

Output:

Area of rectangle: 50

 

Explanation:

  • The function area() takes two arguments: length and width.
     
  • We passed the values 10 and 5 as positional arguments.
     
  • The function correctly calculates the area as 10 × 5 = 50.
     

If we mistakenly switch the order of arguments, it will not affect the result in this case. However, in some cases, swapping positional arguments may cause errors or incorrect results.

Difference between Keyword and Positional Argument

In Python, function arguments can be passed in two ways:

  1. Positional Arguments – Passed based on their position.
     
  2. Keyword Arguments – Passed using the parameter names.
     

Let's look at an example where we compare both types.

Using Positional Arguments

def student_info(name, grade):
    print(f"Student Name: {name}, Grade: {grade}")

student_info("John", "A")
You can also try this code with Online Python Compiler
Run Code

 

Output:

Student Name: John, Grade: A

Using Keyword Arguments

student_info(grade="A", name="John")
You can also try this code with Online Python Compiler
Run Code

 

Output:

Student Name: John, Grade: A

Key Differences

ParametersPositional ArgumentKeyword Argument
Order of PassingMust be in orderCan be in any order
ReadabilityLess readableMore readable
UsageSimple functionsComplex functions

Frequently Asked Questions

What happens if I pass arguments in the wrong order?

If the order of positional arguments is incorrect, the function may produce incorrect output or raise an error.

Can I mix positional and keyword arguments?

Yes, but positional arguments must come first before keyword arguments.

When should I use keyword arguments instead of positional arguments?

Use keyword arguments when the function has multiple parameters and you want to make the function call more readable.

Conclusion

In this article, we learned about positional arguments in Python, which are arguments passed to a function in a specific order. Their position determines their value inside the function. Understanding positional arguments helps in writing clear, structured, and efficient functions while avoiding common errors related to argument misplacement in Python programming.

Live masterclass