Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Skills:
Python for Data90%
Key Takeaways
This video tutorial covers iteration by item using for loops in Python, including syntax and examples for iterating through lists and checking for specific values.
Full Transcript
hey guys welcome back uh today we're doing the ninth video in my Python Programming series and today we're going to be talking more uh more about for Loops so a more advanced type of for Loop in terms of iterating through a list so you may remember a few videos ago we talked about for loops and I mentioned that there are two main type of for Loops that we can use um and the one that we talked about there was looked like this so we had for X in range and then we had a range like this and we simply printed out the numbers like this so we see we got 1 to 10 just like that okay uh so that was the for Loop we talked about there um but the one we're going to be doing today is a little bit different so I'll leave this here for an example uh so the first thing we need to do is we need to make a list because we're actually going to be iterating through every item or every element in the list so again I'm just going to use the same example I used in the other video fruits and I'm going to make it equal to we're going to have apples pears and strawberries strawberries just like that okay so we have our fruits here and now um we're going to get right into the Syntax for this new for Loop so we're going to do four and then any variable name we'd like so in this case I'm going to use fruit and then we're going to use the keyword in once again and then instead of typing range this time we're going to type the name of the list we want to iterate through so in this case it's going to be be called fruits just like that and now um we can print out the fruit sorry the fruit just like that so pretty much what is going to happen is we have a list with three items in it we have apples pears and strawberries now we want to print every fruit in that list so we do that by saying for fruit in fruits meaning for every item in fruits so one two and three items we simply want to print out that fruit so this Loop is going to run three times and we're just going to print out every fruit inside of the list just like this and there you go we have apples pears and strawberries just like that um so yeah that's pretty much how you can iterate through a list and same thing if I want to add more elements to the list so at 8 um 90 just like that again it'll just simply print out all of the items in the list now uh why might we do this you say well there's a few reasons we may want to iterate by item rather than by indices so the other one uh the in range is known as iterating by indic or by index well this one is known as iterating by item so there's a few reasons we might want to do this but the first one is if we only want to print something out uh if it's a certain value so we just want to check through all of the items in the list and see if they are certain value and if they are then we're going to print it out or we're going to do something specific to that item uh so in this case I'm going to say if fruit is equal to for example pairs then I want to print out pairs so we'll just print out the fruit but if it's not equal to pairs so anything else then I will print out not pairs like that so this is an example of how we can look through every item in the list um and simply check if it is a certain value and then if it is we're going to print it to the screen so we'll try this and we see we have not pairs Pairs and Then followed by a few more not pairs um so that's a good way to do it by item um otherwise we can still do this using Indy uh it's just a little more complicated or not as efficient so we could do 4X in range and then in this case we'll do zero and six because we have to do it six times because there's six items in the list and then we'll put a colon and then we'll say the same thing so except this time we're going to say if fruits followed by the square brackets and then X because this is going to be our indic equals equals pairs then we want to print fruit or fruit X oops otherwise we'll print not a pair just like we did in the other loop not a pair okay so we'll run that and we see we get it twice just because I had two for Loops there so it does work uh the exact same way except you can see that this one takes longer to write because we actually have to put the list name followed by the square brackets whereas in this Loop all we have to do is simply type in fruit um because it's automatically going through the list um another reason too we may want to do that is because in this case we had to actually see how many items were in the list by counting um and then we had to put that number in whereas here it'll just stop at the end of the list automatically um now we could do this so Len this is a new word so I'm just showing this now uh this means length and then inside we can put something like a string or a list so in this case I'm going to put the length of fruits and that would give us a value of six and you'll see if I just get rid of this that it'll work the same way again um by using the length of fruits okay so that is how to iterate through a list by item uh I hope you enjoyed if you did please leave a like And subscribe and stay tuned for more videos in this series
Original Description
This is the 9th video in my python programming tutorial series. Today I talk about how to iterate through a list by item using a for loop. This is a continuation from my 6th video where I talk about basic for loops.
Text-Based Tutorial: https://techwithtim.net/tutorials/python-programming/beginner-python-tutorials/iteration-by-item-for-loops-continued/
As always please LIKE and SUBSCRIBE for more content daily!
Video Tags:
python,python tutorial,python language,python full course,python course,learn python,learn python programming,python tutorial for beginners,python tutorial 2018,python programming tutorial,python programming language,software development,programming tutorial,tech with tim
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 10 of 60
1
2
3
4
5
6
7
8
9
▶
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: Python for Data
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
This ChatGPT Prompt Replaced 3 Hours of PowerPoint Work
Medium · AI
This ChatGPT Prompt Replaced 3 Hours of PowerPoint Work
Medium · ChatGPT
How AI Assist Turns a Rough Draft into a Polished Document in Minutes
Dev.to · paperquire
13 ways to make money with AI in 2026, ranked by how fast you will see your first dollar.
Medium · AI
🎓
Tutor Explanation
DeepCamp AI