Skip to main content
Noble Desktop/2 min read

Using For Loops in Python

Python Essentials

Data Types

int, float, str, list, dict, set, tuple — the basic vocabulary.

Control Flow

if/elif/else, for, while — the logic of any program.

Functions

def, return, *args, **kwargs — reusable units of behavior.

Modules & Imports

import statements, packages, virtual environments.

Master Python at Noble Desktop

Noble Desktop's Python Programming Immersive covers AI APIs, data analysis, and modern Python development.

In this video, we're going to look at how to use a For Loop in Python

Video Transcription

Hi, my name is Art and I teach Python at Noble Desktop. In this video, I'm going to explain to you how to use a for loop in Python. You probably heard that there are different types of loops in Python. There is a for loop, which we call a definite loop because we know how many times it will run. Then there is a while loop, which is a different type of loop and it depends on the condition.

Here, I'm going to show you how to use a for loop. It's really simple. Suppose you want to say hello to all of your friends. Feel free to use your own friends and let's say I have a list container with many names: John, Mark, and Mary. So suppose I want to say hello to Mark, hello to John, and hello to Mary. How would I do that?

I need to iterate, I need to go through this list and grab value by value, so that's why we need to use a for loop. To use a for loop, you always need to begin with the keyword 'for'. Then we have to come up with some kind of variable name, let's say 'name'. Then there is a colon and indentation. Here, I'm going to print 'hello' and comma 'name'.

If I run this, you see I'm getting 'hello Mark', 'hello Mary', 'hello John'. That's what the for loop does. It kinda goes through that sequence of items, grabs an item and assign it to 'name'. So under the hood it works like this: 'name' is being defined as 'John', 'Mark', and 'Mary'.

That's it! Watch my next video and I'll show you how to use a while loop and I'll explain you the difference between a definite for loop and a while loop.