Aren't Python strings immutable? Then why does a + “ ” + b work?
问题 My understanding was that Python strings are immutable. I tried the following code: a = \"Dog\" b = \"eats\" c = \"treats\" print a, b, c # Dog eats treats print a + \" \" + b + \" \" + c # Dog eats treats print a # Dog a = a + \" \" + b + \" \" + c print a # Dog eats treats # !!! Shouldn\'t Python have prevented the assignment? I am probably missing something. Any idea? 回答1: First a pointed to the string "Dog". Then you changed the variable a to point at a new string "Dog eats treats". You