Getting the three processes python

Three python flow control program, also known as the three flow control program flow, when we write code, how the program is running, use to control program flow.
Three processes are:
1. sequence: In the normal code, the direction running from top to bottom, left to right.
2. branches (also called selection) Structure: When the code encounters different situations, different options, implementation code is not the same as
① single branch:

		if 条件:
			  #强制缩进,缩进一定要保持一种,不能改变
			(条件成立的情况下,执行缩进的代码)
			  #条件运算的结果必须是布尔值,表示条件是否成立 

Disadvantages: can only handle condition is established, no way to deal with the condition is not established
② double branch:

			if 条件 :        if 条件 :
				Print             	if 条件 :
			else :			  			print
    			  Print 			else :
										print

③ multi-branch:

			If 条件1 :
				Print
			 elif 条件2 :
				条件2成立时的动作
			 elif 条件3 :
				条件3成立时的动作

else: (else can not write, or not write condition indicates otherwise)
biantennary example: Here Insert Picture Descriptionmulti-branch, for example:
Here Insert Picture Description
3 cycles:
Python only two cycles

1.while循环
	语法结构:
		While condition(条件) :

All code # indented, are loop
pass: Skip

2.for循环
	语法结构:
		for in 结构,类似于其他语言中的foreach
		for in 容器:

# Loop
#for in circulation is constantly iterative nature of the container, each iteration will be a container element until the iteration is complete

·for u in users

(For loop, once again pick up elements of users, and then placed in u, every time the previous value will scour)

·容器:代指一块内容
·range的全局函数:至少要有一个参数,表示一个区间范围,range(num)→[0,num)

1. A parameter: from 0 until the front end of a parameter
2 two parameters: range (num1, nume2) → start from num1 to num2-1
3. three parameters: range (num1, num2, i ) → i It represents the number of the interval between the execution of

①continue关键字:出现在循环中,目的是跳过本次循环,执行下次循环;循环是否终止,就要看条件判断;

②break关键字:遇到break关键字,不管条件是否满不满足,都直接终止循环。

· In python, the end of the cycle, may be followed by a else (and while, for the same level)

While :
	Pass
Else :

For :
	Pass
Else :

(This case else belongs to the cycle, when the cycle ends normally (not interrupted BREAK), the process proceeds else
when interrupted BREAK, else not enter; else i.e. after the end of a normal cycle entry)

for example the cycle (the multiplication table):
Code:
Here Insert Picture Description
The results:
Here Insert Picture Description
the while loop example:
Code:
Here Insert Picture Description
The results:
Here Insert Picture Description

Published 17 original articles · won praise 2 · Views 372

Guess you like

Origin blog.csdn.net/qq_44487069/article/details/104418354