+ 1

Please explain me why is this so? # inside

Can't figure out why these operations lead to different results. I thought that "a += x" is a compact version of "a = a + x", but it doesn't act the same way. https://code.sololearn.com/c6elVIArduRn/?ref=app

20th Jun 2022, 7:59 AM
Alex Kravchenko
Alex Kravchenko - avatar
1 Answer
+ 1
Because b acts as a reference to a. Then when a is reassigned, using the different method, b is considered a new list. Seen here by printing the ids before and after https://code.sololearn.com/c7qgg20P3ql0/?ref=app
20th Jun 2022, 12:04 PM
Slick
Slick - avatar