A console/terminal demo of variables and object identity in Python: literal values, id() and the interning of small integers, how two names can point at the same mutable dictionary, and conversion between int, float and str. Runs on Windows 11 and Ubuntu Linux 24.04, uses the standard library only — no third-party packages, no GPU, fully offline.
[Folder Structure]
- CLAUDE.md / AGENT.md: program specification (identical content).
- CHANGELOG.md: change log.
- copyright.txt: copyright notice.
- src/: the example, the launcher scripts, and this document.
- venv/: Python virtual environment, created by step 1.
[Prerequisites]
- Operating system: Windows 11 or Ubuntu Linux 24.04.
- Python 3 and pip.
- No third-party packages — the example uses the standard library only.
- No internet connection and no GPU required.
[Instructions]
Step 1: Create the virtual environment
Create the virtual environment. Because the example uses only the standard library, this step installs no extra packages.
Windows 11:
src\01_venv_create.bat
Ubuntu Linux 24.04:
bash src/01_venv_create.sh
Step 2: Activate the virtual environment
Activate the environment in the current shell. On Linux you must source the script so the activation stays in effect after it finishes.
Windows 11:
src\02_venv_activate.bat
Ubuntu Linux 24.04:
source src/02_venv_activate.sh
Step 3: Run the variable demo
Run the demo. It assigns literal values and prints their id(), shows that two names holding the same small integer share one object, changes a dictionary through one name and prints it through the other, and finally converts values between int, float and str.
Windows 11:
src\03_variable.bat
Ubuntu Linux 24.04:
bash src/03_variable.sh
Step 4: Remove the virtual environment
When you are finished, delete the venv/ folder to free up disk space. Re-run step 1 whenever you need the environment again.
Windows 11:
src\99_venv_clear.bat
Ubuntu Linux 24.04:
bash src/99_venv_clear.sh
[Reading the Output]
- The id() values differ from run to run — that is the point of the demo. What matters is which values are equal to each other within one run, not the numbers themselves.
- A variable in Python is a name attached to an object, not a box holding a value. Assignment binds the name to an object; it does not copy the object.
- Small integers are cached by the interpreter, so two names set to the same small number really do share one object and their id() values match.
- A dictionary is mutable: assigning it to a second name creates another name for the same object, so a change made through one name is visible through the other. To get an independent copy, copy it explicitly.
- int(), float() and str() build a new object of the requested type; converting a float to an int truncates toward zero rather than rounding.
[References]
- Variables in Python (Traditional Chinese): blog.kdchang.cc
This SDK is built in AppForAI - AI Dev Tools.
Purchase license separately: USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.