Loops
A loop repeats a block of code. Instead of copy-pasting the same lines over and over, you write them once and tell Python how many times to run them.
Python has two kinds of loops:
forloops — run once for each item in a sequence (a list, a range of numbers, etc.)whileloops — keep running as long as a condition is true
Each time a loop runs through its block of code is called one iteration.
Use the links below to learn how each one works.
Last updated on