Why is Python Slow
Python is an Interpreted language. Languages like C/C++ are relatively fast when compared to Python.
As already mentioned, Python is an interpreted language, while C is a compiled language. Interpreted code is always slower than direct machine code. It takes more instructions in order to implement an interpreted instruction than to implement an actual machine instruction.
Because when we run the Python script, its interpreter will interpret the script line by line and generate output. But in C, the compiler will first compile it and generate an output that is optimized with respect to the hardware. In the case of other languages such as Java and.NET, Java bytecode, and .NET bytecode respectively run faster than Python because a JIT compiler compiles bytecode to native code at runtime.
Before anything, Python instructions should be understood by the CPU. So the Python interpreter checks each statement according to the rules of the Python language such as allocation of memory for storage of the variables, straining out blank spaces and comments from the program, and other related tasks. This process is repeated for each line of the program and adds significantly to the overhead of program execution.
This all makes Python comparatively slower than other Programming languages.