Thursday, November 20, 2025
HomeLanguagesHow to find the number of arguments in a Python function?

How to find the number of arguments in a Python function?

In this article, we are going to see how to count the number of arguments of a function in Python. We will use the special syntax called *args that is used in the function definition of python. Syntax *args allow us to pass a variable number of arguments to a function. We will use len() function or method in *args in order to count the number of arguments of the function in python.
Example 1: 

Python3




def no_of_argu(*args):
     
    # using len() method in args to count
    return(len(args))
 
 
a = 1
b = 3
 
# arguments passed
n = no_of_argu(1, 2, 4, a)
 
# result printed
print(" The number of arguments are: ", n)


Output :  

The number of arguments passed are: 4

Example 2:

Python3




def no_of_argu(*args):
   
    # using len() method in args to count
    return(len(args))
 
print(no_of_argu(2, 5, 4))
print(no_of_argu(4, 5, 6, 5, 4, 4))
print(no_of_argu(3, 2, 32, 4, 4, 52, 1))
print(no_of_argu(1))


Output : 

3
6
7
1
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11925 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6905 POSTS0 COMMENTS
Ted Musemwa
7160 POSTS0 COMMENTS
Thapelo Manthata
6861 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS