Hello there, I’m totally new here.
I started to learn Python through Mike Dane’s YouTube video (which is in the freeCodeCamp channel) and I didn’t understand the variables he uses in the “Build a Translator” section (here is the timestamp and link to the video https://www.youtube.com/watch?v=rfscVS0vtbw&t=9493s).
He wrote:
def translate(phrase):
translation = ""
for letter in phrase:
if letter.lower() in "aeiou":
if letter.isupper():
translation = translation + "G"
else:
translation = translation + "g"
else:
translation = translation + letter
return translation
print(translate(input("Enter word/phrase: ")))
My questions are:
1 - Is the variable ‘letter’ a “set Python variable” that looks as each character and changes them? Or is ‘letter’ just a variable…? I don’t understand how is “sees” the actual letters in the string and translates them.
2 - I also did not understand how the “letter.lower()” will understand that the character regardless of being upper or lower case will still be “read” by the program.
Forgive me for the basic vocabulary to try and explain my question. If it isn’t clear I can try to elaborate.
Thank you.