-
A function is a group of related statements that performs a specific task.
-
Functions help break our program into smaller and modular chunks.
-
As our program grows larger and larger, functions make it more organized and manageable.
- The function needs to be defined before it can be called. Calling a function before its definition will cause an error.
-
Functions can take arguments, which can be used to generate the function output.
-
You can call the same function with different arguments.
-
Even better, you can define functions with more than one argument; separate them with commas.
-
Arguments can be used as variables inside the function.
-
You can have different statements in your functions, working with the argument variables, such as if statements and loops.
-
Once you return a value from a function, it immediately stops being executed.
-
Any code placed after the return statement won’t be executed.
-
A function can only return once, thus, if you need to return multiple values, you can use a list.