What is the difference between shallow copy, deepcopy and normal assignment operation?
The difference between shallow and deep copying is only relevant for
compound objects (objects that contain other objects, like lists or
class instances):
The difference between shallow and deep copying is only relevant for
compound objects (objects that contain other objects, like lists or
class instances):
I’m trying to remove specific characters from a string using Python. This is the code I’m using right now. Unfortunately it appears to do nothing to the string.
Something about the id of objects of type str (in python 2.7) puzzles me. The str type is immutable, so I would expect that once it is created, it will always have the same id. I believe I don’t phrase myself so well, so instead I’ll post an example of input and output sequence.
My understanding was that Python strings are immutable.
Although I have never needed this, it just struck me that making an immutable object in Python could be slightly tricky. You can’t just override __setattr__, because then you can’t even set attributes in the __init__. Subclassing a tuple is a trick that works:
If a tuple is immutable then why can it contain mutable items?
frozendict(dict_obj): Accepts obj of dict type and returns a hashable and immutable dict
I’m a bit confused about modifying tuple members. The following doesn’t work:
From a recent SO question (see Create a dictionary in python which is indexed by lists) I realized I probably had a wrong conception of the meaning of hashable and immutable objects in python.
I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?