A function is a unit of computation. It’s a tool that we design and sharpen for a specific operation. It can also be reused, both by us and other programmers. Better functions improve the modularity, clarity, and maintainability of the program and increase its value overall. Our program is only as effective as its functions.

In many aspects, Python functions are similar to functions in other popular languages. They take parameters, perform computations, and return computed values to the caller, though there are some differences.

We must use functions in any program longer than a dozen lines.

In this chapter, we’ll learn to use the specific Pythonic function design mechanisms:

  • Multiple returns
  • Optional and keyword parameters generators
  • Anonymous functions
  • Functions creating functions

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy