[PYTHON] For Else statement

for-else.py


for fruit in ['banana','apple','orange']:
    #If you break out of the loop in the middle, else will not be executed
    #if fruit ==apple:
        # break
        
    print('I ate ' + fruit)
else:
    print('I ate all!')

This else is more like a try-except relationship than if-else. However, there are documents that are deprecated, such as Effective Python, because it is difficult for humans from other languages to understand.

Recommended Posts

For Else statement
2016-10-30 else for Python3> for:
Python basics ② for statement
[Python] for statement error
[Introduction to Udemy Python3 + Application] 43. for else statement
Python list, for statement, dictionary
[Python / PyQ] 4. list, for statement
Python Exercise for Beginners # 2 [for Statement / While Statement]
Python for statement ~ What is iterable ~
[Python] Multiplication table using for statement
Change the list in a for statement
return statement
while else
while statement
[Introduction to Udemy Python3 + Application] 40.while else statement
How to write a ShellScript Bash for statement
Don't use readlines () in your Python for statement!