FUNCTION


Function

  • In Python, a function is a group of the related blocks of statements that performs a specific or particular task.
  • It breaks the code into smaller and modular chunks which makes it easier to compile.
  • Enables our program to be more manageable, organized.
  • Avoids repetition of the code again and again and makes the code reusable to n number of times.
  • The def keyword is mainly used to mention the function name that is used to implement the function
  • The rules for naming an identifier should also be followed by the name of a function.
  • A function accepts the argument (parameter) that is not mandatory declared.
  • Optional documentation string (docstring) describes what the working of a function implements.
  • The block_func is started with the colon (:), and block statements must be under the same indentation.
  • The return statement is used to return the value a function needs, which can only be one return value and it is optional.

Syntax of Function

def the_function(arguments):
"""docstring"""
block_func
return statement