Do string methods permanently change the string they’re used on?


#1

##Question

##Answer
Unless you assign the variable to be itself with a string method modifying it, then it will remain the same. Using a string method simply performs the action (upper, lower, etc.) and then moves on to the next line without changing the actual string stored in memory. For example, if you print parrot.upper( ) and then print parrot on the next line, you’ll see it’s lowercase again! However, if we actually assign to parrot the uppercase version of itself, it will make a change to the actual string stored in the variable: parrot = parrot.upper( ) followed by print parrot will show you the uppercased string.


FAQ: Learn Python – Strings & Console Output – lower()
#2

No, They only perform the actions be it lower or upper without changing the actual stored string.
The string is permanently changed when you assign to the variable the action be it lower or upper
for example:

parrot = "Norwegian Blue"
parrot = parrot.upper()
print parrot

In the above example, the variable parrot has been assigned uppercase so any string that goes in there shall be displayed in uppercase letters.


#3

Yeah, no, it won’t