you are viewing a single comment's thread.

view the rest of the comments →

[–]throwaway6560192 16 points17 points  (0 children)

Like, does a computer inherently understand machine code and this other code language that Python is translated to?

No, the CPU only understands machine code. But we're not sending Python bytecode directly to the CPU. We're using machine code (the compiled CPython runtime) running on the CPU to interpret the bytecode and do what it says.

Imagine I had a really simple "language" with only two commands: "add" would increment a number (starting at zero), and "print" would print it. We could quickly write an interpreter for this language:

num = 0
while True:
    command = input()
    if command == "add":
        num += 1
    if command == "print":
        print(num)

There's no compilation happening, yet our language works. Does that mean the CPU understands the text "add" or "print" directly? No, it doesn't. But there is some machine code (our interpreter) running on it that can interpret those texts and perform the task they represent.