*args in Python

Configurare noua (How To)

Situatie

The special syntax *args in function definitions in python is used to pass a non-key worded, variable-length argument list to a function.

The syntax is to use the symbol * to take in a variable number of arguments; by convention, it is used with the word args.

Solutie

Pasi de urmat

# *args for variable number of arguments
def myFun(*argv):
for arg in argv:
print (arg)

myFun(‘This’, ‘is’, ‘a’, ‘test’)

Output:

This
is
a
test

Tip solutie

Permanent

Voteaza

(14 din 29 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?