Python Bytes
#231 Go Python, Go!
- Autor: Vários
- Narrador: Vários
- Editor: Podcast
- Duración: 0:44:13
- Mas informaciones
Informações:
Sinopsis
Watch the live stream: Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training pytest book Patreon Supporters Special guests: Cecil Phillip Brian #1: For-Else: A Weird but Useful Feature in Python Yang Zhou After a for loop, you can put an else block. The else block only executes when there is no break in the loop. If the loop got all the way to the end, and off the end, the else block will run. First, I’m not used to putting break or else anywhere in my Python code, so I’m also curious why you’d want to do this. Yang explains the feature, then talks about 3 scenarios for use: Iterate and find items without needing a flag variable. break when you find what you are looking for, and the else only runs if you didn’t find it. Help to break out of nested loops I’m still confused by this one Help to handle exceptions Kind of a cool use. try/except in a for loop. Have a break in the except block. Then the else block will be fore code where y