For vs while loops in Python: when to use each + practical examples

Pubblicato il: 29 marzo 2023
sul canale di: Pybites
4,285
38

Welcome back to another Python video. Today we look at the difference between for vs while loops:

You use a for loop to iterate over a collection of a finite number of items.
You use a while loop when the number of loops is not known.

We show a couple of simple examples and as while loops are less common, we also dug up two more examples from our coding platform.

We also show a lesser-known construct: for...else (which also would work with a while loop).

Hope this helps distinguish between the two type of loops better.

Please comment below if you want to see videos on more beginner topics ... thanks.


In questa pagina del sito puoi guardare il video online For vs while loops in Python: when to use each + practical examples della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Pybites 29 marzo 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 4,285 volte e gli è piaciuto 38 spettatori. Buona visione!