KIIT Polytechnic logo Students Hub KIIT Polytechnic साइन इन
▲बोर्ड ◆नोट्स ≡सिलेबस ▦टाइमटेबल ?डाउट ▶रील्स 🎮सीखें 🐍कोर्स ◈मौके ✍ब्लॉग ▮स्टोर ★टीम ⌕खोजें
← Learn to Code — Python for Beginners मॉड्यूल · Repeating Yourself

for loops

A loop repeats a set of instructions without you writing them out again and again.

for i in range(5):
    print(i)

This prints 0 1 2 3 4 — range(5) gives five numbers, starting at 0. Python counts from 0 by default, which trips up almost everyone at first.

You can also loop directly over a list of things:

branches = ["CSE", "ETC", "Mechanical", "Civil", "Electrical"]
for b in branches:
    print(b)

Try it: the starter code prints the first 10 square numbers — run it, then change it to print cubes instead.