KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

What are the components of a function?

Python Functions

1 Like

Answer

The various components involved in defining a function in Python are as follows:

  1. Function Header — It is the first line of the function which contains the keyword def, function name and a list of parameters followed by a colon (:). It is also termed as function prototype.
  2. Function Body — A set of statements used within a function header under same indentation. The function header along with the function body is referred to as a Function Block.
  3. Function Name — A specific name given to the function that should preferably relate to the operation being carried out.
  4. Function Signature — The function name along with the number of arguments used while invoking a function.
  5. Parameter List — A list of variables which receives the values passed during a function call.
  6. Return Statement — The statement which sends back the value (result/outcome) from a function to its caller program. It is also called Function Terminator.
  7. Arguments and Parameters — The values passed to the function during its call are called arguments (actual parameters) and the variables defined in the function header that receive these values are called parameters (formal parameters).

Answered By

2 Likes


Related Questions