DEF function in Python

  • The Python Def function is the User-Defined one.
  • Function blocks start with the keyword def then followed by the function name and parentheses ( ( ) ).
  • Any input parameters must place inside the parentheses. Now you can define parameters inside the parentheses.
  • The initial statement of a function is optional statement – the documentation string of the function (docstring).
  • Within the code block each and every function begins with (:) colon and is indented.
  • The statement return [expression] exits the function, alternatively passing back the expression to caller. The return statement with no arguments is the similar as return none.
def function in python

Syntax:

def functionname( parameters ):
   "function_docstring"
   function_suite
   return [expression]

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,