Open In App

Python - Passing list as an argumnet

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

When we pass a list as an argument to a function in Python, it allows the function to access, process, and modify the elements of the list. In this article, we will see How to pass a list as an argument in Python, along with different use cases.

We can directly pass a list as a function argument.

Python
def print_list(a):
    for item in a:
        print(item)

# Define a list of numbers
a = [1, 2, 3, 4, 5, 6]
print_list(a)

Output
1
2
3
4
5
6

Modifying the Original List

When a list is passed to a function, the function can modify the original list since lists are mutable.

Python
def add_item(items, new_item):
    items.append(new_item)

# Define a list 'a'
a = [1, 2, 3]
add_item(a, 4)
print(a) 

Output
[1, 2, 3, 4]

Passing a Nested List

Python also allows passing a nested list (a list within a list) as a function argument. :

Python
def nested_list(nested_list):
    for sublist in nested_list:
        for item in sublist:
            print(item)

# Define a nested list
a = [[1, 2], [3, 4], [5, 6]]
nested_list(a)

Output
1
2
3
4
5
6

Using *args for Unpacking

We can use the *args syntax to unpack the elements of a list and pass them as separate arguments to a function:

Python
def print_items(*args):
    for item in args:
        print(item)

# Define a list 'a'
a = [1, 2, 3]
print_items(*a)  

Output
1
2
3

Article Tags :
Practice Tags :

Similar Reads