compilation - When using the Python Interpreter, is the compiler used at all? -


in google's python class reads

python dynamic, interpreted (bytecode-compiled) language

i know interpreter , know bytecode 2 seem not fit. after doing reading became bit clearer python source code automatically compiled before interpreted; new questions emerged.

when using python interpreter no compilation happen? if does, when? example if you're typing code @ command line , gets run each time hit enter, when compiler have opportunity work?

also in linked question above, @delnan gives pretty broad definition of compiler

a compiler is, more generally, program converts program in 1 programming language program in programming language...jit compilers compile native machine code @ runtime

i guess question is: what's difference between interpreter , automatic compiler? refine question bit, if python compiled, why not compile way machine code (or assembly, since know writing compilers can produce pure machine code difficult)?

perhaps best forget semantics , try learn cpython doing. when invoke cpython binary, number of things. speaking, can expect translate code you've written sequence of bytecode instructions. "compiling" stage people reference python code. these more compact , efficient way tell interpreter hand-written code. frequently, python cache these files reuse in .pyc files (only re-generating if associated .py file newer). can think of python bytecode set of instructions python virtual machine can run -- in lot of ways, it's not different java. when people speak of compiled languages (e.g. c), compiler's job translate code set of instructions run directly on computer's hardware. languages cpython , java have level of indirection (e.g. virtual machine). virtual machine runs directly on computer's hardware , responsible interpreting domain specific language.

compared standard "compiled" languages (e.g. c, fortran), stage light-weight -- , python doesn't lot of checking "traditional" compilers (e.g. typechecking). pretty checks syntax , few simple optimizations using the peephole optimizer.