Data in Gym 101 - For Loop in Python: Essential Techniques for Data Engineers
Basic of For in Python
The purpose of this series is to reinforce some knowledge I have been studying recently and that I believe could help others interested in Data Engineering.
I intend to cover all areas related to Data Engineering, with short and direct posts on interesting and essential topics for a Data Engineer’s daily work.
Let’s start with Python!
In this first post about Python, I will talk a little about the for loop and how it works, with some specific examples for the world of Data Engineering.
For Loop
Basically, the for loop is used to iterate over an object in Python. For example, going through all the items in a list:
Loops are essential for automating repetitive tasks.
We can use any name for the variable inside the for loop, but it is advisable to use a name that makes sense in relation to the items contained in the list:
Working with Numbers
We can use the for loop to iterate through and generate numerical ranges, and for that, we use range:
It’s important to consider Python’s default behavior (off-by-one), where indexing starts at 0.
So, if we want to represent a sequence from 1 to 5, we should write it like this:
This is the first post about the for loop; we will dive deeper in the coming weeks.
Here’s an example of a code snippet commonly used in a Data Engineer’s daily work, using the for loop to iterate through multiple paths in a list:
It may seem complicated at first, but it's important to understand the usability of the for loop in a Data Engineer's daily tasks.
In the next posts, we will dive deeper into the for loop and break down each step of the code above.






