Clarification on Immutability please
On 2020-01-22 01:52, Ethan Furman wrote:
> On 01/21/2020 10:55 AM, Michael Torrie wrote:
>> returns a new object whether one is slicing a tuple, list, or a string,
>> the latter two are mutable objects.
> Strings are not mutable.
In the case of tuples and strings, if the slicing encompasses the entire
object, the original object is returned:
>>> t = (0, 1, 2)
>>> t[:] is t
>>> s = "012"
>>> s[:] is s
Those are safe optimisations because they are immutable objects.