1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

For Else文

Last updated at Posted at 2020-02-10
for-else.py
for fruit in ['banana','apple','orange']:
    #途中でループから抜ける場合はelseは実行されない
    #if fruit ==apple:
        # break
        
    print('I ate ' + fruit)
else:
    print('I ate all!')

このelseはif-elseよりtry-exceptの関係に似ている。
ただし他言語から来た人間には理解しづらいためEffective Pythonなど非推奨としている文献が存在している。

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?