Loops 11 - For your Strings - Question


I finished this one okay by imitating the example but I was wondering:

How does the computer know that the letter "c" here refers to all of the letters in the string and not just, for instance, the exclamation mark or the letter "m" or whatever? If your string contained a "c" would it get confused?


I do not think you understand what a variable is doing in these instances.

To sum it up, you are using variables. Their value changes based on what you are doing to it, or remain static if you program them that way.

word = 'WORD'
for number, letter in enumerate(word):
    print(number, letter)

While you can most definitely name a variable what ever you please I generally go along with a simple rule. Name them something that defines what they will hold or do.

If you do not follow this rule it makes it harder to read your code and leads to confusion and a lot of the times to bugs that are harder to fix because you did not properly name your variables.