PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

for Loop in Python

← All stacks

Theory

22/268

for Loop in Python

for walks each item in an iterable, one by one. Shape: for name in names: print(name). You can loop a list, a string, a tuple, dict keys, or range. range(5) is 0..4. range(1, 6) is 1..5. The stop is exclusive — that off-by-one mistake prints 1..6 when you wanted 1..5.

enumerate(names) gives index and value together: for i, n in enumerate(names):. Dry-run: for i in range(1, 4): print(i) → 1 then 2 then 3. Say the stop is exclusive before you write the code.

for Loop in Python — output — 1 2 3 4 5 each on a new line. range(1, 6) stops before 6.

Diagram
names = [Asha, Ravi, Neha]
         │
         ▼
   for x in names:
       Asha → Ravi → Neha
Exam tip

range stop is exclusive — say it clearly.

Example

# for loop
for i in range(1, 6):
    print(i)

for Loop in Python — output: 1 2 3 4 5 each on a new line. range(1, 6) stops before 6.

Short notes

  • Deffor x in iterable.
  • Rulerange stop is exclusive.
  • Rememberenumerate for index.

Questions

1

Explain for Loop as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with for Loop?

Previous← Loops in PythonNextwhile Loop in Python →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.