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.
Download
0 formats
No download links available.
For vs while loops in Python: when to use each + practical examples | NatokHD