What does def in python mean?

silencement
Release: 2019-06-25 14:28:22
Original
45790 people have browsed it

What does def in python mean?

Python functions

Function is an organized, reusable code segment used to implement a single or related function.

Function can improve the modularity of the application and the reuse rate of the code. You already know that Python provides many 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 with the functions you want. The following are simple rules:

1. The function code block begins with It starts with the def keyword, followed by the function identifier name and parentheses ().

2. Any incoming parameters and independent variables must be placed between parentheses. Parameters can be defined between parentheses.

3. The first line of the function statement can optionally use a documentation string - used to store function descriptions.

4. The function content starts with a colon and is indented.

5.return [expression] End the function and optionally return a value to the caller. Return without an expression is equivalent to returning None.

Syntax

Python defines functions using the def keyword, the general format is as follows:

def 函数名(参数列表):
    函数体
Copy after login

By default, the parameter value and parameter names are matched in the order defined in the function declaration.

Example

Let us use a function to output "Hello World!":

>>>def hello() :
   print("Hello World!")
Copy after login

Output result

> ;>> hello()

Hello World!

The above is the detailed content of What does def in python mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
def
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!