Summary

We've looked at a number of Python features for function definition. We've looked at how we define the name, and the parameters to a function, providing default values to make parameters optional. We've also looked at how we can provide arguments to a function: we can provide arguments by position, or by using the parameter variable name as a keyword. We can evaluate function(*args) to map a sequence of values to parameters by position. We can also evaluate function(**kw) to map a dictionary of values to parameters by name. And, of course, we can combine these two techniques.

We've looked at how functions return values via the return statement. We've also looked at functions which don't return a value. Technically, they return a value of ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.