Skip to content

Magenaut

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

python-internals

Python string interning

August 21, 2022 by Magenaut

While this question doesn’t have any real use in practice, I am curious as to how Python does string interning. I have noticed the following.

Categories Python, Q&A Tags internals, python, python-internals, string, string-interning 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

How does swapping of members in tuples (a,b)=(b,a) work internally?

August 21, 2022 by Magenaut

In [55]: a = 5 In [56]: b = 6 In [57]: (a, b) = (b, a) In [58]: a Out[58]: 6 In [59]: b Out[59]: 5 How does this swapping of values of a and b work internally? Its definitely not using a temp variable. Answers: Thank you for visiting the Q&A section on … Read more

Categories Python, Q&A Tags iterable-unpacking, python, python-internals, tuples Leave a comment

When is del useful in Python?

August 21, 2022 by Magenaut

I can’t really think of any reason why Python needs the del keyword (and most languages seem to not have a similar keyword). For instance, rather than deleting a variable, one could just assign None to it. And when deleting from a dictionary, a del method could be added.

Categories Python, Q&A Tags del, dictionary, python, python-internals Leave a comment

Why does id({}) == id({}) and id([]) == id([]) in CPython?

August 21, 2022 by Magenaut

Why does CPython (no clue about other Python implementations) have the following behavior?

Categories Python, Q&A Tags cpython, identity, python, python-internals Leave a comment

‘order’ of unordered Python sets

August 20, 2022 by Magenaut

I understand that sets in Python are unordered, but I’m curious about the ‘order’ they’re displayed in, as it seems to be consistent. They seem to be out-of-order in the same way every time:

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

About Python’s built in sort() method

August 20, 2022 by Magenaut

What algorithm is the built in sort() method in Python using? Is it possible to have a look at the code for that method?

Categories Python, Q&A Tags algorithm, python, python-internals, sorting Leave a comment

Are tuples more efficient than lists in Python?

August 19, 2022 by Magenaut

Is there any performance difference between tuples and lists when it comes to instantiation and retrieval of elements?

Categories Python, Q&A Tags list, performance, python, python-internals, tuples 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

Why does a class’ body get executed at definition time?

August 19, 2022 by Magenaut

In contrast to functions, a class’ body is executed at definition time:

Categories Python, Q&A Tags class, python, python-internals Leave a comment
Older posts
Newer posts
← Previous Page1 Page2 Page3 … Page5 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