Home  >  Article  >  Backend Development  >  How to customize functions in python

How to customize functions in python

王林
王林Original
2020-05-12 11:33:435390browse

How to customize functions in python

Custom function syntax:

Python custom function uses def keyword, the general format is as follows:

def 函数名(参数):
  
    ...

    函数体

    ...

The definition of function mainly has the following points :

1. def: keyword representing the function

2. Function name: the name of the function. The function will be called based on the function name in the future

3. Function body: in the function Perform a series of logical calculations, such as: sending emails, calculating the maximum number in [11,22,38,888,2], etc...

4. Parameters: Provide data for the function body

5. Return value: After the function is executed, data can be returned to the caller.

Code example:

# 定义函数
def test_a():
    print('hello world')
# 调用函数
test_a()

Recommended tutorial: python tutorial

The above is the detailed content of How to customize functions in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn