Skip to content

Magenaut

  • Home
  • Topics
    • Notes
    • Tutorial
    • Bug fixing
    • Extension
    • Server
  • Q&A
  • Privacy Policy
  • About

immutability

What is the difference between shallow copy, deepcopy and normal assignment operation?

August 22, 2022 by Magenaut

The difference between shallow and deep copying is only relevant for
compound objects (objects that contain other objects, like lists or
class instances):

Categories Python, Q&A Tags copy, deep-copy, immutability, python, variable-assignment Leave a comment

Remove specific characters from a string in Python

August 21, 2022 by Magenaut

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.

Categories Python, Q&A Tags immutability, python, replace, string Leave a comment

About the changing id of an immutable string

August 21, 2022 by Magenaut

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.

Categories Python, Q&A Tags immutability, python, python-internals, string Leave a comment

Aren’t Python strings immutable? Then why does a + ” ” + b work?

August 20, 2022 by Magenaut

My understanding was that Python strings are immutable.

Categories Python, Q&A Tags immutability, mutability, python, string Leave a comment

How to make an immutable object in Python?

August 20, 2022 by Magenaut

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:

Categories Python, Q&A Tags immutability, python, python-3.x Leave a comment

Why can tuples contain mutable items?

August 19, 2022 by Magenaut

If a tuple is immutable then why can it contain mutable items?

Categories Python, Q&A Tags immutability, list, python, python-internals, tuples Leave a comment

What would a “frozen dict” be?

August 19, 2022 by Magenaut

frozendict(dict_obj): Accepts obj of dict type and returns a hashable and immutable dict

Categories Python, Q&A Tags data-structures, dictionary, immutability, python Leave a comment

a mutable type inside an immutable container

August 18, 2022 by Magenaut

I’m a bit confused about modifying tuple members. The following doesn’t work:

Categories Python, Q&A Tags immutability, list, mutable, python, tuples Leave a comment

Hashable, immutable

August 18, 2022 by Magenaut

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.

Categories Python, Q&A Tags data-structures, hash, immutability, python Leave a comment

Why are python strings and tuples are made immutable?

August 16, 2022 by Magenaut

I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?

Categories Python, Q&A Tags immutability, python, string, tuples Leave a comment
Older posts
Page1 Page2 Next →
  1. michealSmith07 on Is there a way to dynamically refresh the less command?August 21, 2022

    That is a very nice post. I like this post.

  2. anonymous on Fix libwacom9 dependency issue when upgrade DebianJune 27, 2022

    saved my day!! Thanks for the help…

  3. sreedhar on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    Thanks its working

  4. saintnick on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    remove libwacom2 worked for me as well

  5. ranafoul on Fix libwacom9 dependency issue when upgrade DebianApril 22, 2022

    apt remove libwacom2 helped on kali 2022.01. gr8

.net ajax asp.net asp.net-core asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-web-api bash c# command-line css custom-post-types custom-taxonomy dataframe dictionary django entity-framework functions gridview html iis javascript jquery json linux list matplotlib numpy pandas php plugin-development plugins posts python python-2.7 python-3.x security shell shell-script sql string vb.net webforms wp-query

© 2026 Magenaut • Built with GeneratePress