Usually, when using scripts you reuse a lot of code. Instead of copying the entire code, you can define a function with that code and call it when you need it.
Functions combine several operations under one name. This lets you streamline your code. You can write out a set of statements and define the block of statements as a function and give it a name. Then the entire block of statements can be executed by calling the function and passing in any information the function needs. If a function is given a name that describes what it does, it will be easier to read and understand the code. It will hide details and make your scripts more modularized.
You pass information to a function by enclosing the information in parentheses after the name of the function. Pieces of information that are passed to a function are called arguments or parameters. Some functions do not take any arguments at all while others take one or more arguments. In some functions, the number of arguments depends on how you are using the function.
A function call is a statement used to invoke a function. Use the function name followed by parentheses containing the arguments, if any, to do a function call:
FunctionName(p1,p2,...,pn)You always have to use the parentheses, even if a function contains no arguments:
FunctionName()A function may or may not return a value.