Home  >  Article  >  Backend Development  >  What does fun mean in python?

What does fun mean in python?

(*-*)浩
(*-*)浩Original
2019-07-04 10:07:3130563browse

fun in python means function. Functions are organized, reusable code segments used to implement a single or related function.

What does fun mean in python?

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. (Recommended learning: Python video tutorial)

Define a function

You can define a function with the function you want. The following is simple Rules:

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

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

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

The function content starts with a colon and is indented.

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

Syntax

def functionname( parameters ):
   "函数_文档字符串"
   function_suite
   return [expression]

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

Example

The following is a simple Python function that takes a string as an input parameter and prints it to a standard display device.

#python2.0+
def printme( str ):   "打印传入的字符串到标准显示设备上"
   print str
   return

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What does fun mean 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