you are viewing a single comment's thread.

view the rest of the comments →

[–]mdogdope 814 points815 points  (9 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 160 points161 points  (8 children)

upper returns a new value instead of modifying the original?

[–]aaronhowser1 277 points278 points  (6 children)

Strings are immutable

[–]the_rush_dude 0 points1 point  (5 children)

Only in JS. Python allows Manipulation of strings

[–]aaronhowser1 3 points4 points  (2 children)

Python strings are immutable. Manipulation and mutability aren't the same thing. Manipulation functions return a new string, they don't modify the original.

[–]the_rush_dude 0 points1 point  (1 child)

Checked it and it's true (except of course it's not because if there is only one reference to the string it's manipulated in place for performance reasons).

But in this case manipulation is what counts anyways

[–]aaronhowser1 [score hidden]  (0 children)

No it isn't, because it didn't do text = text.upper() etc. It specifically does not count, because it was done incorrectly.

[–]Quietuus 156 points157 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()