Python path [Article 4]: Python-based functions, Article 4

Source: Internet
Author: User

Python path [Article 4]: Python-based functions, Article 4
Function understanding

Process-oriented: code from top to bottom according to business logic

Function: encapsulate a function code into a function. You do not need to write it again later. You only need to call the function.

Function is used to ensure good scalability and reusability of your program.

If the same function is used more than three times, we recommend that you use the function.

Special understanding:

Functions can be understood as one function block. You can split a large function into one block and call a function block when using a function!

Functions can be understood as Lego blocks. You can use these blocks to form any function you want!

Functions can call functions! The main function is to concatenate and call functions! The function itself cannot be executed by itself. If it is not called, it will never be executed!

# ----------------------------------------------- Def func1 (): passdef func2 (): passdef func3 (): passdef func4 (): pass func1 () func2 () func3 () func4 () if _ name _ = '_ main _': # Call the above function. The function is judged and called cyclically! # You can also call the function example in the function: def func4 () :#__ name _. This is used to judge, if you import this program as a module, its _ name _ is equal to the program file name. If you manually execute this script, for example, python test. in py, _ name _ is equal to _ main _. Therefore, we can use it for judgment. if you execute it manually, I will call the function to execute the statement below if, if you call the if statement in the module to determine whether the statement is executed! Only used by modules! # If a function is imported into a module, the name of the function is imported, and the content is not imported, the function information will be imported only when you call the function.

 

Directory 2

Test .............. 2

Subdirectory 3

Test ......

Directory 4

Test ......

Directory 5

Test ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.