Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:10:35+00:00 2026-05-24T09:10:35+00:00

Why is Python’s intern built-in only for strings? It should be possible to extend

  • 0

Why is Python’s intern built-in only for strings? It should be possible to extend intern to classes that are hashable and comparable, right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:10:36+00:00Added an answer on May 24, 2026 at 9:10 am

    The purpose of interning things is to be able to compare them by comparing their memory address; you ensure that you never create two objects with the same value (when the program requests the creation of a second object with the same value as an existing object, it instead receives a reference to the pre-existing object). This requires that the things you’re interning be immutable; if the value of an interned object could change, comparing them by address isn’t going to work.

    In Python, it’s not possible to enforce the immutability of user-defined class instances, so it wouldn’t be safe to intern them. I suspect that’s the main theoretical reason intern doesn’t cover class instances.

    Other built in immutable types are either comparable in a single machine-level operation already (int, float, etc), or immutable containers that can contain mutable values (tuple, frozenset). There’s no need to intern the former, and the latter can’t be safely interned either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python's inner/nested classes confuse me. Is there something that can't be accomplished without them?
Python's convention is that variables are created by first assignment, and trying to read
Python documentation says that os.rename(src, dst) ... On Windows, if dst already exists, OSError
python newbie here. I'm writing the code to control an experiment that has multiple
Python has the idea of metaclasses that, if I understand correctly, allow you to
Python loves raising exceptions, which is usually great. But I'm facing some strings I
Python 2.6+ and 3.* have next(), but pre-2.6 only offers the object.next method. Is
Python does not provide built-in support for multi-dimensional arrays. I need to develop an
Python Decimal doesn't support being constructed from float; it expects that you have to
Python, C++, Scheme, and others all let you define functions that take a variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.