Using For Loops in Python

Free Video Tutorial and Guide

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'.

Python for Data Science Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

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.

photo of Noble Desktop

Noble Desktop

At Noble Desktop you can learn how to code websites, build iOS apps, make graphics, and more. From our front-end coding bootcamp to Photoshop classes, we offer a variety of comprehensive day, evening, and weekend training classes as well as certificate programs in web design, web development, HTML email, and more. Courses are available in-person (at our training facility in Soho), live online, and customized corporate or private training. Our course materials and workbooks are used by colleges and schools worldwide. Learn a skill today and start using it tomorrow.

More articles by Noble Desktop

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram