A function is reusable code that can be called anywhere in your program. Functions improve readability of your code: it’s easier for someone to understand code using functions instead of long lists of instructions.
On top of that, functions can be reused or modified which also improve testability and extensibility.
Python Programming Bootcamp: Go from zero to hero
We use this syntax to define as function:
The def keyword tells Python we have a piece of reusable code (A function). A program can have many functions.
We can call the function using function(parameters).
The function has one parameter, x. The return value is the value the function returns. Not all functions have to return something.
We can pass multiple variables:
If you are new to Python programming, I highly recommend this book.