Python Learning Road 8 - Introduction to Functions

  1. What is the function?

Before learning functions, we have always followed procedural programming, that is, implementing functions from top to bottom according to business logic, which often uses a long piece of code to implement specified functions.

The most common operation in the development process is to paste and copy, that is, to copy the previously implemented code block to the required function.

In this way, the final program will become very verbose. Is there any way to do something with these same code blocks?

Making the code of the program appear simple and clear, which leads to the content of today's study: functions.

Definition: A function refers to a set of statements encapsulated by a name (function name). To execute this function, just call its function name.

Features: Reduce repetitive code, make programs extensible, and make programs easier to maintain.

   2. Define the function

1  def function name (parameter):
 2       
3      ....
 4      function body
 5      ....
 6      return return value
 7   
8 function name ()

   Function composition: function name, parameters, function body, return value, which will be described in detail next.

   3. Common parameters

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325172064&siteId=291194637