Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialZahkyi Ferguson
504 PointsWhen will strings become immutable?
As it stands now we are able to go back and edit our strings, how long will this last for?
2 Answers
Steven Parker
231,269 PointsStrings are always immutable, but the variables that hold them can be re-assigned with a new value.
For examples:
s = "string"
s = "test" # re-assignment is ok
s[2] = "x" # but this will cause an error because the string is immutable
Andy Hughes
8,479 PointsNot sure what you mean but as far as I know, strings are immutable unless you use concatenation, splitting etc, but you'd still need to create a new object from the original.