pub-3785248829033902 | Python: *args | - Big data with Python

| Python: *args |

*args allows us to pass variable number of arguments to the function. 


The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the args statement in Python:

Æ’ python command

def add(*args):
    i = 0
    for k in args:
        i += k
    print("The sum is", i)

add(1,2)
add(1,2,3)
add(1,2,3,4)

output

The sum is 3
The sum is 6
The sum is 10


Previous
Next Post »