Python中while循环的⽤法
#while循环,不断地运⾏,直到指定的条件不满⾜为⽌。
count = 1
while count <=5:
print(count)
count += 1
'''
1
2
3
4
5
'''
#while 循环的退出可以使⽤标志flg退出,break退出等
#使⽤标志退出
count = 1
active = True
while active:
print(count)
if count >= 5:
active =Fal
el:
count += 1
珍惜作文'''
1
2
3
4
5
'''
#break 退出
count = 1
while True:
print(count)
if count >= 5:
足球的由来break
el:
count += 1
'''
1
2
3
4
诸葛亮的品质5
无法访问u盘
'''
#continue,返回到循环开头,并根据条件测试结果决定是否继续执⾏循环
count = 1
while count <= 5:
if count % 2 ==0:
count += 1
continue
el:
print(count)
梯形的概念count += 1
'''
1
3
5
'''
#在列表之间移动元素
unconfirmed_urs = ['alice', 'brian', 'candace']
confirmed_urs = []
while unconfirmed_urs:计算机基本操作
confirmed_ur = unconfirmed_urs.pop() #弹出列表末尾的元素 print('confirmedur:' + confirmed_ur)
电锅炉供暖confirmed_urs.append(confirmed_ur)#在列表中添加元素print("\nThe following urs have been confirmed:")
for confirmed_ur in confirmed_urs:
print(confirmed_ur.title())
'''
confirmedur:candace
confirmedur:brian
confirmedur:alice
The following urs have been confirmed:
Candace
Brian
Alice
'''
#删除列表中包特定的元素小学语文课程标准
pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'catt']
print(pets)
while 'cat' in pets:
print(pets)
'''
['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'catt']
['dog', 'dog', 'goldfish', 'rabbit', 'catt']
'''