有没有什么方法可以继续for循环而不转到下一个索引
示例:
for player in range(players):
name = input("what is your name? ").lower()
if name == "john cena":
print("Hey! That's not your real name!")
[some keyword or function that allows the magic to happen]
elif name == "donald trump":
print("Hi Mr. President!")
[the same keyword or function that allows the magic to happen]
player_names.append(name)
外壳:
============ RESTART =========
what is your name? luke
what is your name? john cena
Hey! That's not your real name!
what is your name? donald trump
Hi Mr. President!
what is your name? mickey mouse
what is your name? nobody
>>> player_names
["luke", "mickey mouse", "nobody"]
for
循环允许您对每个元素迭代一次,而不必担心如何实际移动到下一个索引如果您需要更多地控制何时或是否要移动到下一个索引,可以使用
while
循环相关问题 更多 >
编程相关推荐