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 9243715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:52:02+00:00 2026-06-18T08:52:02+00:00

This is python code. for e in range(-10, 10): exec(‘x=%d’% e) exec(‘y=%d’% e) print

  • 0

This is python code.

for e in range(-10, 10):
    exec('x=%d'% e)
    exec('y=%d'% e)
    print e, id(x), id(y), x is y

I expected the print statement shows only Trues.
But it is not. under -5, that shows False.

Result is

-10 38832080 38832056 False
-9 38832032 38832080 False
-8 38832056 38832032 False
-7 38832080 38832056 False
-6 38832032 38832080 False
-5 30857416 30857416 True
-4 30857392 30857392 True
-3 30857368 30857368 True
-2 30857344 30857344 True
-1 30857320 30857320 True
0 30857296 30857296 True
1 30857272 30857272 True
2 30857248 30857248 True
3 30857224 30857224 True
4 30857200 30857200 True
5 30857176 30857176 True
6 30857152 30857152 True
7 30857128 30857128 True
8 30857104 30857104 True
9 30857080 30857080 True

Why exec assigns different id to x and y respectively under -5?

  • 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-06-18T08:52:03+00:00Added an answer on June 18, 2026 at 8:52 am

    CPython caches small integers between -5 and 256. See PyInt_FromLong:

    The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object.

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

Sidebar

Related Questions

/Users/smcho/Desktop/bracket/[10,20] directory has abc.txt, but when I run this Python code import glob import
I have this code in Python inputted = input(Enter in something: ) print(Input is
I'm trying to convert this Python code to C. But for the life of
I'm trying to write python code to print the powerset of a string, but
Given this piece of code(python) s = [None]*10 def func(): for i in range(10):
Consider this Python code for printing a list of comma separated values for element
I was given this Python code that would calculate an MD5 value for any
This is my Python code - cursor.execute(UPDATE tasks SET task_owner=%s,task_remaining_hours=%s, task_impediments=%s,task_notes=%s WHERE task_id=%s, (new_task_owner,new_task_remaining_hours,new_task_impediments,
I perform this kind of query in my Python code to conn = rdbms.connect(instance=_INSTANCE_NAME,
I've inherited some python code that contains a rather cryptic decorator. This decorator sets

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.