python基础之循环
while循环
message = ""
while message != 'quit':
message = input("Enter 'quit' to end the program: ")
if message != 'quit':
print(message)
循环标志
active = True
while active:
message = input("Enter 'quit' to end the program: ")
if message != 'quit':
print(message)
else:
active = False
break退出循环
while True:
message = input("Enter 'quit' to end the program: ")
if message != 'quit':
print(message)
else:
break
countinue退出
current_number = 0
while current_number < 10:
current_number += 1
if current_number % 2 == 0:
continue
print(current_number)
while循环处理列表
unconfirmed_users = ['alice', 'brian', 'candace']
confirmed_users = []
while unconfirmed_users:
current_user = unconfirmed_users.pop()
print("Verifying user: " + current_user.title())
confirmed_users.append(current_user)
print("\nThe following users have been confirmed:")
for confirmed_user in confirmed_users:
print(confirmed_user.title())
删除多个特定元素
pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']
print(pets)
while 'cat' in pets:
pets.remove('cat')
print(pets)
本文来自博客园,作者:Harry_666,转载请注明原文链接:https://www.cnblogs.com/harry66/p/13765311.html