From the course: Advanced Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Variable argument lists

Variable argument lists - Python Tutorial

From the course: Advanced Python

Start my 1-month free trial

Variable argument lists

- [Narrator] Just like some other programming languages, Python functions support variable argument lists and this makes it possible to build functions that have a high degree of flexibility by accepting different numbers of parameters. A good example of this might be an addition function that adds up the parameters passed to it. Now it would be pretty inconvenient to require cause of this function to have to conform to putting all the numbers into a list. So defining the function to accept a variable list of parameters would be a better way to go. To do this in Python, you define the function argument using an asterisk character in front of the parameter that you want to make variable. This parameter has to come after all the other positional parameters that the function defines. For example, if we built a logging function that logged messages along with parameter values, we would maybe first define the parameters for the message type and the message and then specify the variable…

Contents