Python Passing Multiple Arguments Without Declaration

In Python, with the help of *args you can pass any number of arguments to a function without specifying the number.

def add_numbers(*numbers):
       sum = 0
       for number in numbers:
           sum += number
       return sum
print(add_numbers(5,6,233,56,3,5,2,5)) ## 315

By specifying **kwargs you can pass any number of keyword arguments to a function.

If you have any questions about this code, you can drop a line in comment.

Comments

Popular posts from this blog

Python chr() Built in Function

Python float() Built in Function

Python bool() Built in Function

Python Printing Readable Results

Python exec() Built in Function