Home >Backend Development >Python Tutorial >What are the definitions and calls of python functions

What are the definitions and calls of python functions

coldplay.xixi
coldplay.xixiOriginal
2021-03-09 17:16:0823112browse

Definition and calling of python functions: 1. Do you use the def keyword to define the function? The code is [def function name (parameter 1, parameter 2, parameter 3...)]; 2. The function must be defined first , can be called, otherwise an error will be reported.

What are the definitions and calls of python functions

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.

Definition and calling of python functions:

1. Function definition

1) Use def keyword to define function

2)

def 函数名(参数1,参数2,参数3...):
    """文档字符串,docstring,用来说明函数的作用"""
    #函数体
    return 表达式

The role of the comments here: explain what the function does and what functions the function has.

3) Indent when encountering a colon. All indented code blocks after the colon constitute the function body, which describes what the function does, that is, what the function does

python The essence of a function is consistent with the essence of a function in mathematics

2. Calling a function

1) The function must be defined first before Call, otherwise an error will be reported

2) Function call without parameters: function name (), function call with parameters: function name (parameter 1, parameter 2...)

3) Do not call itself in the function body when defining a function, otherwise you will not be able to get out, and will fall into a loop call

4) The function needs to call the function body to be executed. Simply defining the function will not Executed

5) Step Into(F7) in the Debug tool enters the called function, and Step Into My Code(Alt Shitf F7) enters the function in the called module

Related free learning recommendations: python video tutorial

The above is the detailed content of What are the definitions and calls of python functions. 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