HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Glossary
  2. /Python and data
  3. /For Loop

What is For Loop?

In short

A for loop repeats a block of code once for each item in a sequence, such as a list or a range of numbers.

In simple words

for x in marks: takes each item of marks in turn and names it x. The code that is indented underneath runs once for each item. range(5) gives 0,1,2,3,40, 1, 2, 3, 40,1,2,3,4: it starts at 000 and stops before 555. Use a for loop when you know how many times to repeat, and a while loop when you repeat until something happens.

Example

This prints 15, which is 1+2+3+4+51 + 2 + 3 + 4 + 51+2+3+4+5.

Learn it properly

  • Lessons on this topic
  • Test yourself

Related terms

  • While Loop (Repeat Until)
  • List (in Python)

← All glossary terms

Learn it in

  1. Repeat with for: Loops
  2. Repeat Until: while Loops
All lessons on this topic →

Practise

  1. This loop should show the even numbers from 2 up to and including 10…Medium
  2. Write a program that asks for a password, again and again, until the user types python123…Medium
  3. Find the first number from 100 upwards that can be divided by both 6 and 8…Easy
  4. Asha saves 45 rupees every week, and has 0 at the start…Easy

Quick questions

  1. A for loop prints its numbers with no space and no new line between them. The sequence…Hard
  2. A while loop takes numbers from the end of a list until it meets a zero. What does the…Hard
  3. A loop uses pass and a statement after the if and else blocks. What does the program…Hard

More Python and data terms

  1. Cell (in a Python notebook)
  2. Class and Special Methods (in Python)
  3. Dictionary (in Python)
  4. Function (in Python)
  5. If Statement (in Python)
  6. Import (Python modules and libraries)
All Python and data terms →

Try it yourself

Python labs run in your browser. Type the code, run it and see what happens.

Open a Python lab