The definition of a function specifies exactly how a function is constructed, what parameters are passed to it, and what value it returns to the calling function.
With the declaration we name a variable and make it known to the compiler.
Definition and declaration differ in some points. The definition includes a memory allocation for the function, while no memory is allocated in the declaration. The declaration can be done several times, vice versa a function can be defined exactly once in a program.
In Python, functions are defined with the keyword
def followed by the function name and the input parameters.
def function_name(): # code to be executed def function_name(parameter_1 = default_value, parameter_2 = default_value, ...): # code to be executed
def add(): # code to be executed
|1||Defines the function |
|2||The function returns the sum of |
def add(a = 3, b = 5): return a + b