When I’ve been working with C# or C++, I can choose the Build or Compile option to build or compile my program. Then I can run it provided there are no errors.
When I did a Python program earlier tonight after I wrote my code and looked into the Build menu I did not see a compile or build option. All I had to do is hit CTRL + F5 to run my program.
Just wondering why Python doesn’t need to be built.
Because it’s an interpreted language? Building is not necessary? I don’t know.
Indeed it is not about the Python programming language itself. It is about the tool used. As far as I know, the Python programming language itself does not dictate anything about whether or not there should be a discrete compilation step nor which kind of compilation should be used.
The key difference between scripting languages and compilation-required languages is whether or not they use the same language for declaring their code structure as they use for executing algorithms.
In Java/C/C#/C++/etc, the top level structure of a module (class definitions, module usage declarations, function definitions, etc) differs from the algorithmic language used inside function and method definitions. As a result, you can’t just “run a module” - you have to build the module into an executable program, and then run the declared execution entry point (usually some kind of main function or method). A lot of symbol lookups get resolved across modules at compilation time in these languages, so the compilation step is mandatory, and an explicit part of the development workflow when using them.
In a scripting language (like Python or a shell script), the module itself can be executed directly, with execution starting at the top of the module and then proceeding statement by statement. Symbol resolution across modules also occurs at runtime rather than at compile time, so the modules can all be compiled in isolation from each other, rather than needing to be compiled as one integrated program. This module independence, and relative speed and simplicity of the associated language compiler, makes it practical to compile modules implicitly as they are needed (either via execution or via import). Explicit precompilation is still possible, but it isn’t necessary (and most IDEs won’t provide a button for it).