Comment on page
A function is a group of statements that exist within a program for the purpose of performing a specific task. Another way to think about a function is that it gives a name to a concept that you might want to reuse.
- Functions represent an idea.
- Functions should do one thing - and one thing well!
Procedural programming is a programming paradigm based upon the concept of the procedure call. Using functions, also known as procedures, is an example of procedural programming.
- 1.Simpler Code - Code tends to be simpler and easier to understand when it is broken into functions.
- 2.Code Reuse - Functions reduce duplication of code within a program.
- 3.Easier to test - When each task is contained in its own function, testing and debugging become simpler.
A function contains a header and body. The header begins with the def keyword, followed by the function’s name, parameter(s) or argument(s) and ends with a colon.
Calling a function executes the code in the function. To use a function, you have to call it. If the function returns a value, a call to that function is treated as a value.
When a function is called, the control is is transferred to the function. When the function is finished, the control is returned to where the function was called.
The main function is the starting point of our program.
print("Hello function world!")