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

Publié le: 29 mars 2023
sur la chaîne: 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.


Sur cette page du site, vous pouvez voir la vidéo en ligne For vs while loops in Python: when to use each + practical examples durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Pybites 29 mars 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 4,285 fois et il a aimé 38 téléspectateurs. Bon visionnage!