Word Up PygLatin


I've already completed the lessons but there is something that I still don't understand quite yet.

It gives us the code

the_string = "Hello"
the_string = the_string.lower()

The .lower() function does not modify the string itself, it simply returns a lowercase-version. In the example above, we store the result back into the same variable.

Now here's my question: what does it mean by "it does not modify the string itself"? It does modify it to the point where it prints out a lowercase-version?

Second question: what does the_string do?

Thanks in advance.


When use have the_string = "Hello" the_string has an upper case letter. When we use the_string.lower() the original variable still has an uppercase letter, that string is not changed, but we are returned a new string. So, if we have
the_string = "Hello"
the_new_string = the_string.lower()
then the_string would have an uppercase letter and the_new_string would be all lowercase, the original string, that is the_string, is unchanged.

the_string is just a variable name, it doesn't do anything aside from hold a value.


well look:

the_string = "Hello"
another_variable = the_string.lower()
print the_string

see how .lower() hasn't manipulated the string? the string stored in the variable the_string is still the same

how .lower() exactly works under the hood i don't know, but i guess it makes a copy of the original string

the_string is just a variable, you could have named it anything


Thanks for the fast answer as usual! You'll be seeing me often here as I'll be asking frequently when I'm unsure if I understand something.

So basically...

the_string = "Hello"
another_variable = the_string.lower()
print the_string

You have created a new variable another_variable that holds the_string.lower() is not to "damage" the original the_string?

And by the way, when we want to have a lowercase version of something, do we always need it to store it into another variable?

Again, thank you!!


No, i stored the result in a different variable to prove the original string is preserved, maybe better to prove with this code:

the_string = "Hello"
print the_string.lower()
print the_string

No, we don't. We can store it in the same variable, overwriting what was original in the variable (but then the overwrite is not caused by .lower()) or in a different variable, or not at all, by just printing it/doing a comparison with it. So much possibility's.


Thanks for the answer!


Makes sense. Also, by "different variable" in your last sentence you mean as the case here? And what do you mean by doing a comparison with it?


EDIT: Never mind, I was just a little confused. I understood what you meant by reading it a few times.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.