Types of Arguments in Python

In Python, when we call a function, we pass values (called arguments) to it. These arguments can be passed in different ways depending on the situation.

There are mainly 4 types of arguments in Python:

  1. Positional Arguments
  2. Keyword Arguments
  3. Default Arguments
  4. Variable-Length Arguments (*args, **kwargs)

1. Positional Arguments

In positional arguments, the values are passed to the function in the **same order** as the parameters are defined. This is the most common way of passing data into functions.

The position matters — the **first value** goes to the **first parameter**, the **second value** to the **second parameter**, and so on.

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

student_info("Angel", "A")

Output:

Student Name: Angel
Grade: A

Explanation:

  • The function student_info() has two parameters: name and grade.
  • When we call it as student_info("Angel", "A"), the first argument "Ananya" is assigned to name.
  • The second argument "A" is assigned to grade.
  • This method depends on the correct order. If you change the order, the meaning changes.

2. Keyword Arguments

In keyword arguments, we pass values by **mentioning the parameter names explicitly**. Here, the **order doesn’t matter** because Python matches values using the parameter names.

student_info(grade="A", name="Angel")     # calling the previous function

Output:

Student Name: Angel
Grade: A

Explanation:

  • Even though the order is reversed, Python knows that grade="A" should go to the grade parameter and name="Angel" to name.
  • This makes the code more **readable** and **less error-prone**, especially when a function has many parameters.
  • Also helpful when we only want to pass a few parameters and skip the rest (if they have default values).

3. Default Arguments

When we provide a default value to a parameter, we can skip it while calling.

For detailed examples and explanation, Click here to continue reading.

def greet(name, age=18):
    print("Name:", name)
    print("Age:", age)

greet("Peehu")

Output:

Name: Peehu
Age: 18

  • If age is not provided, it takes default value 18.

4. Variable-Length Arguments

*args → Non-keyword variable-length arguments

For detailed examples and explanation, Click here to continue reading.

def add(*numbers):
    total = 0
    for n in numbers:
        total += n
    print("Sum:", total)

add(5, 10, 15)

Output:

Sum: 30

**kwargs → Keyword variable-length arguments

def show_details(**info):
    for key, value in info.items():
        print(key + ":", value)

show_details(name="Devanshi", age=20)

Output:

name: Devanshi
age: 20

Explanation:

  • *args collects extra positional arguments in a tuple.
  • **kwargs collects extra keyword arguments in a dictionary.

Summary Table:

Type Description Example
Positional Based on order of arguments greet("A", 20)
Keyword Based on parameter names greet(age=20, name="A")
Default Function has default values def f(a, b=10)
*args Many positional values add(1, 2, 3)
**kwargs Many keyword values show(name="A")

Welcome to ShikshaSanchar!

ShikshaSanchar is a simple and helpful learning platform made for students who feel stressed by exams, assignments, or confusing topics. Here, you can study with clarity and confidence.

Here, learning is made simple. Notes are written in easy English, filled with clear theory, code examples, outputs, and real-life explanations — designed especially for students like you who want to understand, not just memorize.

Whether you’re from school, college, or someone learning out of curiosity — this site is for you. We’re here to help you in your exams, daily studies, and even to build a strong base for your future.

Each note on this platform is carefully prepared to suit all levels — beginner to advanced. You’ll find topics explained step by step, just like a good teacher would do in class. And the best part? You can study at your pace, anytime, anywhere.

Happy Learning! – Team ShikshaSanchar