day-1Python基础循环for、while,判断if

1.if条件判断

a=4
if a==3:
    print('正确,a的值为3')
else:
    print('错误!')

>>:错误

2.for循环

for i in range(4):#range(3) range(start, stop[, step]) 如:range(4,7,2) 输出4,6
    print(i)
>>:
0
1
2
3

3.while循环

i=1
while i<5:
    print(i)
    i += 1;

4.break跳出循环

i=1
while i<5:
    print(i)
    i += 1;
    if i==3:
        break
>>:
1
2

5.continue继续下一次循环

while i<5:
    i += 1;
    if i==3:
        continue
    print(i)
>>:
2
4
5

猜你喜欢

转载自blog.51cto.com/13803166/2128486