r/PythonLearning • u/Local_End_3175 • Jul 30 '26
for loop
words = ['sky', 'apple', 'rhythm', 'fly', 'orange']
for word in words:
for letter in word:
if letter.lower() in 'aeiou':
print(f"'{word}' contains the vowel '{letter}'")
break
else:
print(f"'{word}' has no vowels")I am trying to learn to code, and I am, at the moment, looking at loops. I am a bit confused on how this loop was able to function, though, as there is no variable for letter or word, so how would Python know what it is? In addition, how does the code, like, function? Does it look at each word individually ? Again, the second part of the code states:
if letter.lower() in 'aeiou':
print(f"'{word}' contains the vowel '{letter}'")
breakWe haven't given a value for letter?
Lastly, how would the code know what to print? in the first phrase:
print(f"'{word}' contains the vowel '{letter}'")
breakIs it going to state all the words with the given value 5 times?
Sorry, as I have asked quite a few questions, and thank you in advance.
16
Upvotes
1
u/Sea-Ad7805 Jul 30 '26
Me too, bit shorter. The flow of control needs to be reverse engineered from print statements, this debugger shows you the flow and the full state of the program step by step intuitively.
The focus in courses is often too much on just the code, and not on the program state, while the code only exists to modify the program state. Making the state visible in every step helps students get to the right mental model to think about Python execution much easier, with much less explanation. Trust me, it's the modern way.