Functions of Python

Source: Internet
Author: User

Python functions:

Functions are well-organized, reusable pieces of code that are used to implement a single, or associated function.

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:

Define a function that you want to function, the following is a simple rule:

  • 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, and the parentheses can be used to define the 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.
Grammar

The Python definition function uses the DEF keyword, and the general format is as follows:

def function name (argument list):    function Body

Functions of Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.