Python functions
Functions are well-organized, reusable pieces of code that are used to implement a single, or associated function.
Unlike a function definition in mathematics, a function can be called a subroutine in a computer.
Functions can improve the modularity of the application, and the reuse of the code. You already know that Python provides a number of built-in functions, such as print (). But you can also create your own functions, which are called user-defined functions.
Define a function
You can define a function that you want to function, and here are the simple rules:
- The function code block begins with a def keyword followed by the function identifier name and parentheses ().
- Any incoming parameters and arguments must be placed in the middle of the parentheses. Parentheses can be used to define parameters.
- The first line of the function statement can optionally use the document string-for storing the function description.
- The function contents begin with a colon and are indented.
- return [expression] ends the function, optionally returning a value to the caller. Return without an expression is equivalent to returning None.
Syntax of the function
def functionname (Parameters): " Function _ Document string " function_suite return [expression]
By default, parameter values and parameter names are matched in the order defined in the function declaration.
Python Entry 11th Day _ function