What is the mechanism of + = operation and = + operation of a string?

-sharp a
>>> a = "s2@"
>>> id(a)
49220672
>>> a = a + "s"
>>> id(a)
49220672
>>> a += "@"
>>> id(a)
49220672
-sharp a
>>> a = "-sharp$@-sharp$@"
>>> id(a)
49220544
>>> a += "23"
>>> id(a)
49302888
>>> a = a + "sd"
>>> id(a)
49302888
-sharp a
>>> a = "@-sharp$-sharp@%"
>>> id(a)
49220608
>>> a += "^%&%&"
>>> id(a)
49302728
>>> a = a + "&^**%$^"
>>> id(a)
49296880

what causes three different results.

Oct.21,2021

the reason for this is the pooling mechanism in python. Simple and commonly used shorter strings are stored in memory and memory pooling technology is used to improve performance.

For more information, please refer to the answer understands pooling in python

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e53685-597b6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e53685-597b6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?