Python圈软件测试Python基础

Python3--条件判断与循环控制

2020-08-24  本文已影响0人  伊洛的小屋
1.条件判断与循环控制
# 伊洛Yiluo
# https://yiluotalk.com/
>>> password = 123456
>>> input_password = int(input('Please input password to login: '))
Please input password to login: 654321
>>> if input_password == password:
...     print('login successfully!')
... else:
...     print('Password ERROR, Please Retry~')
...
Password ERROR, Please Retry~
2. if 中常用到的运算符
3. 可以使用 and 和 or 来对符合的条件进行控制
4. pass 关键字
5. 循环语句
>>> name_list = ['Yiluo', 'Tom', 'Lucy', 'Joe']
>>> for _ in name_list:
...     print(_)
...
Yiluo
Tom
Lucy
Joe
>>> for i in range(8):
...     print(i)
...
0
1
2
3
4
5
6
7
>>> a = 10
>>> while a >0:
...     print(a)
...     a -=1
...
10
9
8
7
6
5
4
3
2
1
>>> a = 10
>>> while a >0:
...     if a == 3:
...         break
...     print(a)
...     a -=1
...
10
9
8
7
6
5
4

a 等于 3的时候 break

>>> for i in range(10):
...     if i == 3:
...        continue
...     print(i)
...
0
1
2
4
5
6
7
8
9

i 等于3 的时候被忽略

欢迎下方【戳一下】【点赞】
Author:伊洛Yiluo
愿你享受每一天,Just Enjoy !

上一篇 下一篇

猜你喜欢

热点阅读