My understanding about interpreted languages like Python is that, it converts (or, compiles, depending on the exact definition of the terms) the source code to low-level and platform-independent bytecode. When bytecode needs to be executed on a specific machine, it will be again converted to target machine-specific machine code by a Python VM so that my Python code (already in bytecode format) could be successfully understood by the CPU of a target machine.
In this procedure, source code and bytecode are platform-independent and the final machine code is platform-dependent.
My question is, what if I save the resultant machine code generated by Python VM and re-use it on the same machine? Does it mean that I already get Python source code compiled just like C/C++? My understanding is, on the machine code level, the concept of "high-level programming languages" disappears and source code which generates such machine code becomes irrelevant--machine code is just machine code, CPU does not care and cannot find out which language such machine code comes from. Does it mean that, somehow, PythonVM-generated machine code can be as fast as C/C++ generated machine code?
(I understand that such machine code will NOT be cross-platform anyway--but this is not the concern of this question. Since I can always compile my source code targeting different platforms just like C/C++.)
No. Python bytecode is not the same as a machine code. Obviously you could build a hardware that uses Python bytecode as machine code.
But instead of creating a real hardware machine, Python devs created a sort of Python Virtual Machine that runs the Python code as its machine code (Im saying sort of, because it's mainly interpreted instead of compiled like JVM languages and the VM is not really a VM but an interpreter, you should study a bit more about the difference between VM and interpreted:-)). You can imagine the VM as a program that "emulates real hardware" for the purposes of running the code.
This way, you don't need to care about the underlying hardware, but you have to ship a Python interpreter environment together with your code to form an executable.
I think that the misconception that there is a direct conversion to machine code is the culprit. In a way, yes, Python is translated to machine code, but sort of indirectly by executing the Python environment on the machine and then the Python environment in the process of executing your code happens to transforms your Python code to machine code in order to run it.
Will interpreted languages like Python be as fast as compiled languages like C++ if I keep the machine code