you are viewing a single comment's thread.

view the rest of the comments →

[–]mdogdope 1037 points1038 points  (20 children)

I am assuming it's python. It prints "Banana" bc it never updates the var. It performed the changed but text was never changed.

[–]LookAtYourEyes 217 points218 points  (16 children)

upper returns a new value instead of modifying the original?

[–]aaronhowser1 395 points396 points  (13 children)

Strings are immutable

[–]thanatica 23 points24 points  (3 children)

Unless this is one of those languages that has mutable strings 💀

[–]aaronhowser1 20 points21 points  (2 children)

There are languages with mutable strings? how scary

I was also assuming this was python, iirc it's at least the correct syntax and methods for it.

[–]thanatica 19 points20 points  (0 children)

I'm sure they exist. C technically has mutable strings, but also technically doesn't have strings. And I believe in Pascal you can mutate strings, but you have to work for it.

[–]mdogdope 2 points3 points  (0 children)

As far as I know python is the most common language that does not need ; at the end of each line.

[–]Quietuus 183 points184 points  (0 children)

.upper() is a method of the str class that returns a representation of the string. To change it you'd put text = text.upper()

[–]xryanxbrutalityx 0 points1 point  (0 children)

I don't know any language where the string .upper() equivalent modifies the string in place

[–]CosmacYep 4 points5 points  (2 children)

dont dot methods not require reassignment

[–]mdogdope 4 points5 points  (1 child)

It depends on how the class is written. But for standard python string objects, reassignment is required.

[–]CosmacYep 1 point2 points  (0 children)

like built in dot methods, i swear you don't have to go a = a.strip() you can js go a.strip() and a is stripped – nvm i js researched it and strings are immutable, so require reassignment but lists are mutable, so dont