Python Forum
Python's id() function output in prompt and script mode
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python's id() function output in prompt and script mode
#2
When you run the code in the interactive interpreter, each statement is compiled separately. On each of the two assignment statements, python creates a int instance, so there are two instances.

If you run the code from the file, all the statements are compiled together and I guess python is smart enough to detect that it only needs to create a single int instance for the two literal constants 500. You could have more information by examining bytecode with the help of the dis module.
Reply


Messages In This Thread
RE: Python's id() function output in prompt and script mode - by Gribouillis - Dec-06-2018, 12:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a function akbarza 9 1,302 Sep-29-2023, 11:13 AM
Last Post: snippsat
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,401 Jun-29-2023, 11:57 AM
Last Post: gologica
  How to print the output of a defined function bshoushtarian 4 1,351 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Open windows cmd prompt and run cmds with python Extra 3 1,481 Jul-14-2022, 06:07 AM
Last Post: Gribouillis
  Real-Time output of server script on a client script. throwaway34 2 2,089 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  output correction using print() function afefDXCTN 3 11,190 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  things that work in terminal mode but not in sublime mode alok 4 2,928 Aug-11-2021, 07:02 PM
Last Post: snippsat
  string function doesn't work in script ClockPillow 3 2,448 Jul-13-2021, 02:47 PM
Last Post: deanhystad
  python prints none in function output chairmanme0wme0w 3 2,276 Jul-07-2021, 05:18 PM
Last Post: deanhystad
  Automatic user/password entry on prompt by bash script PBOX_XS4_2001 3 2,835 May-18-2021, 06:42 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020