Ravindra BagaleCourses & study guides मराठी Track your progress

Python for Loops and while Loops Explained with Examples (range, break, continue)

Ravindra Bagale's Tip — Chala mitrano

A computer is great at doing the same job 10,000 times without getting tired. Loops are how we tell it to. Today we loop over lists, numbers and dictionaries.

What you will learn in this chapter

  • for loops over lists and strings
  • range() for counting
  • Looping over dictionaries and with enumerate
  • Collecting results while looping
  • while loops
  • break and continue
  • List comprehensions — the short form

Practice data

All names, shops, banks, hospitals and amounts in this chapter are made up for learning. They are not real people or real company numbers.

Concepts in this chapter

  1. P6.1How a for Loop Works in Python
  2. P6.2Python range() Function for Counting Loops
  3. P6.3Loop Over Dictionaries and Use enumerate in Python
  4. P6.4How to Build a New List Inside a Loop
  5. P6.5Python while Loop with Examples
  6. P6.6break and continue in Python Loops
  7. P6.7Python List Comprehension Explained Simply