for Loop in Python

Let’s learn what a for loop is in Python and how to write it.

We'll cover the following

Previously, we learned how to count lines present in a file. However, our program was reading all the empty lines as well, which resulted in an incorrect output. In this lesson, we’ll learn how to write a for loop in Python and use it to count the number of lines in a program by ignoring the empty lines.

What is a for loop?

A for loop is a programming concept that, when implemented, executes a piece of code repeatedly “for” a certain number of times, based on a sequence.

Get hands-on with 1200+ tech skills courses.