I was trying out the for loops in Python, and I don't fully understand why it breaks.
When I type:
but when I type:
I also found out I can do:
So what is the key difference here? Why does the first option break the program?
When I type:
for i in catNames: print(catNames[i])the program breaks.
but when I type:
for i in catNames: print(i)I get the desired result.
I also found out I can do:
for i in range(len(catNames)): print(catNames[i])for the same successful result.
So what is the key difference here? Why does the first option break the program?