Python basis - a conditional statement

The if statement

Python programming language specify any non-empty and non-0 (null) is true, 0 is null or false.
Performing, in basic form in the Python programming control program for the if statement is:
determination condition can be used if statement> (greater than), <(less than), == (equal),> = (greater than or equal), <= (less than ! equal), = (not equal) to represent the relationship
if the condition is determined:
execute statement ......
the else:
execute statement ......

Condition is satisfied
Python basis - a conditional statement
condition is not satisfied
Python basis - a conditional statement

When the judgment condition is a plurality of values, the following form:
IF Condition 1 is determined:
execute statement 1 ......
elif judgment conditions 2:
execute statement 2 ......
elif determination condition 3:
execute statement 3 ......
the else:
execute statement ... 4 ...
Python basis - a conditional statement

    嵌套循环

    ![](https://s1.51cto.com/images/blog/201910/10/256eb386133115ee65fe6ce119e836a4.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

while loop

count=0
while count < 9:
print('The count is ',count)
count = count + 1
print('good bye')
以上代码执行输出结果
The count is 0
The count is 1
The count is 2
The count is 3
The count is 4
The count is 5
The count is 6
The count is 7
The count is 8
good bye

无限循环

while 1==1: #该条件永远为true,循环将无限执行下去
执行语句1……

注意:以上的无限循环你可以使用 CTRL+C 来中断循环。

continue,break

count=0
while count < 9:
count = count + 1
if count % 2 > 0: #非双数时跳过输出
continue
print('The count is ',count) #输出双数2、4、6、8

1 = I
the while 1: # 1 must be set up to cycle condition
Print ( "==== I", I)
I + 1 =
IF I> 10: # 10 is out of the loop greater than when
break

while recycling else statement

= 0 COUNT
the while COUNT <. 9:
COUNT = COUNT +. 1
IF COUNT% 2> 0: # the non-skip even number of output
Continue
Print ( 'of The COUNT IS', COUNT) 2,4,6,8-numbered output #
the else:
Print ( "end of the current cycle la la la la")

Guess you like

Origin blog.51cto.com/13729775/2441304