在没有中断功能的循环中,有没有办法在Python中停止代码?例如,如果我给一个文本文件,它看起来像:在没有中断的情况下停止Python中的代码
5 *
7 *
5 *
Limerick
8 A
8 A
5 B
5 B
8 A
Quintain (English)
0 A
0 B
0 A
0 B
0 B
如何,只要它达到一个包含所有字母(在这种情况下,利默里克),而不使用断点功能行停止循环?
for line in file:
list.append(line) until it reaches Limerick and ignore the rest of the file
基本上我想前3行到一个列表,然后停止循环追加不使用断点功能。
你想跳出循环的,但你不希望使用命令明确表示该目的? – khelwood 2014-11-22 02:19:57
“While”循环怎么样? – Himal 2014-11-22 02:21:35
不适合我。这是一个任务,我们不允许使用休息。我不会问是否可以。 – nigerianmahogany 2014-11-22 02:24:41