Jan-10-2019, 01:59 PM
Hey guys,
I was reading python learn-stuff at https://www.programiz.com/python-programming/for-loop
and I was wondering: is the suggested code logical?
I was reading python learn-stuff at https://www.programiz.com/python-programming/for-loop
and I was wondering: is the suggested code logical?
# Program to iterate through a list using indexing genre = ['pop', 'rock', 'jazz'] # iterate over the list using index for i in range(len(genre)): print("I like", genre[i])If I had to code it: I would (a newbie at python!):
# Program to iterate through a list using indexing genre = ['pop', 'rock', 'jazz'] # iterate over the list using index for i in genre: print("I like", i)I don't understand why range+len is needed. Perhaps someone can clearify?