Aren’t Python strings immutable? Then why does a + ” ” + b work?

First a pointed to the string “Dog”. Then you changed the variable a to point at a new string “Dog eats treats”. You didn’t actually mutate the string “Dog”. Strings are immutable, variables can point at whatever they want.

Leave a Comment