Using ELSE with FOR loop
This snippet is an example of how we can use ELSE with a FOR loop in Python
Python: 3.0    Anurag Rana    06 Jul 2021   0
Login to upvote
1
2
3
4
5
6
7
8
9
for word in sentence: 
    if word == "quit": 
        print ("Time to quit" )
        break 
    else: 
        do_something_with(word) 
else: 
    print ("There was no 'quit' in the sentence" )
print ("Now we're done...." )
Copy | Download as: .py file   PNG
Share on: FB   Twitter   LinkedIn   WA
©2021 - code108labs   Contributors   Hosted on DigitalOcean   Partner website: pythoncircle.com