Python strings are immutable, which just means that once created they can't be changed, just like numbers.
If you have 6 apples and I have 6 oranges, then you eat an apple that doesn't mena I have 5 oranges left! :laugh:
Think about it:
x = 666
x = x + 1
y = 666
print(x)
print(y)
You expect that to print 667 and 666 - because if it didn't, code would be a real problem!
How about this:
x = 666
y = x
x = x + 1
print(x)
print(y)
Again, you expect 667 and 666 because
y
holds a copy of the value in
x
not the "same value as
x
"
Strings do the same thing:
x = '666'
y = x
x = x + '1'
print(x)
print(y)
Prints "6661" and "666" because the string is as immutable as a number: once created a string can't be changed, so any attempt creates a new string and returns that instead.
Make sense?