Home python variable parameter functions in Python

variable parameter functions in Python




You need to transfer the functions in advance of the unknown number of arguments. How to declare such functions I know, I would like to know what the call syntax of such a function, provided that the arguments are listed, and the number of arguments is stored in a separate variable.

Answer 1, Authority 100%

Function is declared so

Def Foo (* Args):
  For a in args:
    Print (A)

Star here collects transmitted arguments to the list

Call usual

foo (1,2,3,4,5,6)

call if the arguments are already in the sheet:

lst = [1,2,3,4,5]
Foo (* LST)

Star here decides the list into arguments.

The number of arguments is not used here because lists in python are in size. For SI, such parameters are transmitted by the pointer and the list size there is necessary.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions