在沒有中斷功能的循環中,有沒有辦法在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