Get the App
SLTechnology News&Howtos  ›  Development  › 

The definition, characteristics and skills of Python function

Shulou Source: shulou.com Published: 2022-06-03 19:01:43 10月01日 Update

This article introduces the relevant knowledge of "the definition, characteristics and skills of Python function". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Function characteristics

Hide the details of implementing the function

Reuse code

Improve readability and facilitate debugging

Definition of function

Def function name (formal parameter 1, formal parameter 2,... Parameter n):

Code to run (function body)

Data output by return (return value)

Formal parameters: the format data specified by the function is required for constraints.

Actual parameters: the actual call to the incoming data. Used to pass values.

Return value: the calculation result of the function

After the return statement is executed, the program interrupts execution. The return value None indicates that it does not exist.

The skill of using function

The default value is function (a _ memory b = "usb", c)

Pass parameters in the form of formal parameters: func (name= "zhangsan", age=32) does not have to pass parameters according to the order of formal parameters.

* parameters after representation must be passed by keyword (name,*,age,height) [mixed format]

Sequence pass parameter l = [1 print (* 1)] (calc (* 1)

Dictionary parameter para= {"name": "zhangsan", "age": 32} health_ch (* * para)

The return value contains multiple data

Dict= {"eployer": [{"id": 134, "name": "zhangsan"}],. } name=dict.get ("employer") [0] .get ("name")

Pass parameters in tuple (* tuple)

Random number

Import random import import module

A collection of functions of a module.

Generate a random integer r=random.randint between 1 and 16 (1pc16)

This is the end of the content of "definition, characteristics and skills of Python function". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Functions parameters form data use skills characteristics actual formal parameters formal parameters code content functions more modules knowledge output practical learned next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux Huawei NVidia Apple