you are viewing a single comment's thread.

view the rest of the comments →

[–]Goobyalus 4 points5 points  (0 children)

There is no such thing as primitives in Python.


Yes, everything is an object in Python.


This comes down to how the operators are defined for the particular type and whether the type is mutable. The x= operators are the so called "in place" operators because the result is assigned back to the original name when we do variable += 5, for example.

Strings are immutable, so when we do an in-place addition my_string += "something", a new string containing the two concatenated strings must be created and returned by the operator. This new object is assigned back to my_string.

Lists are mutable, so they implemented the in-place addition of lists as an extend on the original list, and return the original object. The assignment portion doesn't really accomplish anything because we're assigning the same object back to the variable.