Loops are used when we want to perform a task again and again.

Suppose you need to print “hello world” five times:

print("hello world")
print("hello world")
print("hello world")
print("hello world")
print("hello world")

But if you need to print it 100 times, it becomes problematic and repetitive. So we use loops to solve this.

Loops
├── for loop
└── while loop

Note

Loops help reduce repetition and make code cleaner and shorter.

<< Python Match Case | Python While Loop >>