Pythonのfor文にはelse節があります。
公式ではこんな感じで説明されている。
for_stmt ::= "for" target_list "in" expression_list ":" suite
["else" ":" suite]
実際のところ
for s in [1,2,3,range(1,4)][3]: print(s) else: print("fin\n") #>> 1 #>> 2 #>> 3 #>> fin #>>
Pythonのfor文にはelse節があります。
公式ではこんな感じで説明されている。
for_stmt ::= "for" target_list "in" expression_list ":" suite
["else" ":" suite]
for s in [1,2,3,range(1,4)][3]: print(s) else: print("fin\n") #>> 1 #>> 2 #>> 3 #>> fin #>>