What is a function?

A function is a piece of code that runs only when it’s called. We can input data as parameters to a function. We can also get data as output from a function. Our programs extensively use built-in Python functions. Some examples of built-in functions include range(), len(), round(), and print().

We can also define custom functions known as user-defined functions. In this lesson, we discuss how to create and use user-defined functions.

User-defined functions

The syntax for creating a user-defined Python function is given below.

Get hands-on with 1200+ tech skills courses.