Iterate through Items of a List in Python (FOR Loops) – Python Tutorial for Beginners

///Iterate through Items of a List in Python (FOR Loops) – Python Tutorial for Beginners

Iterate through Items of a List in Python (FOR Loops) – Python Tutorial for Beginners

FavoriteLoadingAdd to favorites

🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ Iterate through Items of a List in Python (FOR Loops)

Lists are a very useful and a widely used data structure, in Python. As a developer, you will often be in situations where you will need to iterate through a list, while you perform some actions on its items. So, the most common way to iterate through a list in Python, is with a FOR Loop.

my_list = [‘red’, ‘green’, ‘blue’]

for item in my_list:
print(item)

This works well if you only need to read the items of the List. But, if you want to update them, you need the indexes. A common way to do that, is to combine the range() and len() functions altogether. For instance, this loop iterates through the list and double each item. If you do not know how the range() function works, please check out a suggested video about: Python FOR Loops.

my_list = [1, 2, 3, 4]

for i in range(len(my_list)):
my_list[i] = my_list[i] * 2

# my_list = [2, 4, 6, 8]

○ Length of a List in Python

Eventually, you may want to find how many items a list has. In that case, you do not have to iterate through the entire list and count each item, but use the function len() – which returns the number of items in a list.

my_list = [‘red’, ‘green’, ‘blue’]
print(len(my_list)) # OUTPUT: 3

Let’s play this video, stick around and watch until the end of this video! 👍🏻

– Digital Academy™ 🎓

***

☞ WATCH NEXT:
○ Data Types in Python –
○ Operators in Python –
○ IF Statements in Python –
○ FOR Loops in Python –

☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course]

📖 Blog:

📖 Complete Python Development Course for Beginners [PLAYLIST]:

🛒 Shopping and Discounts:

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡




♡ SUPPORT US ♡


***

source

By |2021-03-29T13:10:56+00:00March 29th, 2021|Python Video Tutorials|12 Comments

12 Comments

  1. Digital Academy March 29, 2021 at 1:11 pm - Reply

    How to iterate through the items of your List in Python? Let’s find out 🤔

  2. Lala Jt March 29, 2021 at 1:11 pm - Reply

    🐍👍

  3. Lala Jt March 29, 2021 at 1:11 pm - Reply

    Your channel is the best

  4. Lala Jt March 29, 2021 at 1:11 pm - Reply

    🙏

  5. Lala Jt March 29, 2021 at 1:11 pm - Reply

    Thank you

  6. chloe jbt March 29, 2021 at 1:11 pm - Reply

    🐍🤩🙏👍

  7. By Cath Test For You March 29, 2021 at 1:11 pm - Reply

    On va devenir incollable sur Python !

  8. By Cath Test For You March 29, 2021 at 1:11 pm - Reply

    Les cours avancent bien !

  9. By Cath Test For You March 29, 2021 at 1:11 pm - Reply

    Hello teacher ! Aujourd'hui je suis là pour la publication !

  10. chloe jbt March 29, 2021 at 1:11 pm - Reply

    Thanks a lot for posting that New video

  11. Jérémy Brandt March 29, 2021 at 1:11 pm - Reply

    This video is very useful when you want to iterate through your List in Python 👍🏻

  12. Jérémy Brandt March 29, 2021 at 1:11 pm - Reply

    Thanks for sharing this video 🙏🏻

Leave A Comment

*