Command Execution :
You enter python hello_world.py in the terminal. The OS locates the Python interpreter and starts it, passing the script as an argument.
Interpreter Initialization :
The Python interpreter initializes, setting up:
Built-in modules (e.g., sys, os).
The _main_ module for the script's execution context.
The Global Interpreter Lock (GIL) for thread management.
Source Code Parsing :
The interpreter reads hello_world.py and checks for syntax errors. If errors exist, it halts and reports them.
Bytecode Compilation :
If no .pyc file exists (or it's outdated), the interpreter compiles the source code into bytecode (low-level, platform-independent instructions).
The AST (Abstract Syntax Tree) is generated as an intermediate step.
The bytecode is saved in a .pyc file (e.g., __pycache__/hello_world.cpython-39.pyc).
Bytecode Execution :
The Python Virtual Machine (PVM) executes the bytecode:
print("Hello, World!") is translated into bytecode instructions (e.g., LOAD_CONST, CALL_FUNCTION).
The PVM interprets these instructions, invoking the print function.
print internally uses C-level functions (via Python’s C API) to write the string to stdout , which eventually triggers OS system calls (e.g., write() on Unix).
Output Handling :
The OS routes the output to the terminal, displaying "Hello, World!".
Cleanup and Exit :
The interpreter deallocates resources (e.g., memory for the string).
Control returns to the OS, exiting with a status code (0 for success).
Nesta página do site você pode assistir ao vídeo on-line When you run a Python script like helloworld.py duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário LearnPy 08 Março 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 7 vezes e gostou 0 espectadores. Boa visualização!