When we compile a Python program, the python compiler converts the Python source code into another code called byte code. Byte code is a fixed set of instructions that represent different types of operations. This code can run on any Operating System and hardware. So mainly, byte code instructions are platform-independent.
The size of each byte code instruction is one byte, and thats why they are called the name byte code.
Now we need to convert the byte code to machine understandable code, which comprises 0s and 1s. This machine understandable code is called machine code.
So Python uses an interpreter called PVM (Python Virtual Machine), which understands the byte code and converts it into machine code.
After that, these machine code instructions are executed by the processor and results are displayed.
(pic: Google)
We can view the python byte code files (.pyc).
First, write a program in any text editor and save it with .py
now, compile the program using python compiler.
for example, if your file name is test.py, then use the following syntax
c:\> python test.py
To see the byte code instructions created by the python compiler before they are executed by the PVM, execute the following command.
c:\>python -m dis test.py
Here -m represents the module named dis. This module is also known as 'disassembler' that displays the byte code in the human-understandable format.
The above command will display the byte code of the test.pyc file creates during the compilation of the test.py file.
That is the way to view the byte code.
Thanks!