Question:
What is the full path taken by python code before it is executed?
How often asked: Rarely
Suggested by: ALittleMoron
Answer:
Before execution, Python code undergoes lexical analysis, followed by syntactic analysis. This is followed by compilation of the program code into bytecode, after which the virtual machine executes this bytecode.
Lexical analysis is the division of the program source code into tokens—the smallest unit of language. The result is a list of tokens.
Syntactic analysis is the checking of input tokens against the grammatical rules of the language. The output is an AST tree.
Compilation to bytecode is the translation of the AST tree into low-level operations understood by the Python virtual machine.
Interview answer explanation:
This question is very rare, but it's still asked occasionally.
Essentially, this question is asking the interviewer how deeply the candidate understands the principles of the language they're coding in. This knowledge isn't practical, unless you're a core Python developer working in C. In that case, this knowledge would be very useful. But in that case, you'd need to understand the language at a much deeper level.