+ 1

Iteratable object

Hi, I am really confused about iterators in Python, I have watched some videos on youtube, but it is not helping me, can somebody please explain me what an iterable object is in Python, with example? Thank you.

13th Jun 2022, 12:34 PM
Danish Zubair
Danish Zubair - avatar
1 ответ
0
In simple terms, they are things that have countable items. A list is an iterable object because we can count how many elements are within the list. And that way, we can also loop over those items. For example: //Below is a list (or an array in many other languages) video_games = ["Gears of War", "Halo", "Stardew Valley", "Half-Life", " Animal Crossing"] //I can now use a for loop to ITERATE (loop over) all the elements in that list. This loop is going over the items one by one. for game in video_games: print(game) The output should be: Gears of War Halo Stardew Valley Half-Life Animal Crossing
13th Jun 2022, 12:41 PM
Justice
Justice - avatar