Loop: loop is a repetitive task. A computer is a very stupid machine. Basically, it only performs simple operations such as addition, subtraction, multiplication, division, greater than, less than, equal to, and loop. Programming is to split complicated problems into simple units for repetition.
Specifically, a loop is to first set a condition and repeat a series of operations when the condition is met. Until the set conditions are no longer met, you can end the loop.
Thanks to the formulas mentioned below, many complicated problems have already been solved. We just need to repeat the formulas that others have prepared to solve.
The biggest advantage of the Python language is that it contains a large number of formulas to solve common problems. What you want is basically done by someone who helps you. You just need to organize them, bind it. For example, the formula for downloading files, the formula for analyzing Web content, the formula for compressing files, and the formula for processing emails.
Formula: it is like a mathematical formula (a + B) 2 = a2 + 2AB + B2. Include a specific value, for example: (3 + 4) 2 = 32 + 2*3*4 + 42 = 9 + 24 + 16 = 49. The previous (a + B) 2 is our formula name. Of course, during programming, we use phrases that are easy to understand as the formula name, such as the square of "and, it can be used in English or pinyin. He needs two parameters A and B. The A2 + 2AB + B2 following is the specific calculation step. This is our formula.
Of course, in programming, our so-called formula is not a mathematical formula, and there is nothing like mathematical derivation or inference. We just bundle the operations we want to do into a heap so that we can reuse these operations in different places. This is the programming formula. In this way, you do not need to repeat the details every time you do the same thing.
For example, washing clothes, making clothes, making soap, rubbing clothes, casting, and wring out all the things that need to be repeated every time you wash your clothes are turned into one thing by the washing machine, as long as you put in different clothes and wash detergent with different weights, you can let him wash them. After that, open the lid and wash them.
This washing machine is our formula. The washing process is the operations that we need to repeat each time. The Washing Machine Factory helps us with the same clothes that we put in each time, washing powder of different weights is a set of parameters used in the formula.
Several small formulas can be combined into a large formula. If you are busy at work, study, do not have time to do housework, or you are just a lazy word, ask a Household Assistant, a household Assistant, a washing machine, a vacuum cleaner, a microwave oven, and so on, coupled with his own operations, combinations, and loops, these small formulas are bundled and become a grand formula. Every time you pay the money, the sanitation will be cleaned and the meal will be ready. The work done by the Household Assistant is a more complicated formula for you. Every time you make an appointment by phone, pay the money to apply the formula for completing housework.
In a program, the term of a formula is "function" or "method ". We define a function, that is, to define a formula. When we use it, we can just set the formula for parameters A, B, and so on.
To make the program structure clear, we often define many functions. Divide complex problems into many small problems. Put each small problem into a function, and then use these small problem functions to solve the big problem. More importantly, we can use a lot of functions written by others to solve our own problems.
The function is used to make the program structure clear and can be applied repeatedly in different places.