A function is a block of statements that returns a specific task.
The idea is to group some frequent or repetitive tasks together to create a function. This allows you to make function calls and use the code inside it over and over instead of writing the same code over and over for different inputs.
Calling Python functions
After creating a function, you can call it with the name of the function followed by parentheses containing the parameters for that particular function. When a function is called, program control passes to the function definition.
All code inside the function is executed.
After the function call, program control jumps to the next statement.
Advantages of using functions
- Reusable Code - The same function can be used multiple times in a program, making the code reusable.
- Code Readability – Functions help break code into smaller pieces to make your program easier to read and understand.