r/learnpython • • Jan 05 '24

Why are interpreters required for programming ?

i'm trying to learn python ....i'm hearing a lot of stuff about interpreters....just wanna know what are they for..why are they required...can i learn python without interpreter...without vs code or py charm

Cuz i wrote some codes in python and it worked without connecting python to interpreter ....why is an interpreter necessary

Plz enlighten me

14 Upvotes

71 comments sorted by

View all comments

1

u/[deleted] Jan 06 '24

Python is an interpreted language which means you can type code into Python and it will interpret it -- parse and run it one line at a time. You can also save code in a .py file and have python interpret the file. Python modules are distributable files of python code that can be imported into other python files.

The advantages of an interpreted language is that you type in code and run it on the fly. You can run your code on any system that has an interpreter for the language, but you have to have the interpreter and any supporting modules running on the computer to run anything. You don't have to wait for compiling and linking every time you run the program, which speeds up debugging and testing.

C on the other hand is a compiled language, like most programming languages. You save C code in a file then you compile it using a C compiler which preprocesses, parses and complies your code into machine code. These days the compiler will automatically link it with compiled library code to produce a stand alone executable, though in the past this was a separate step. Now you have a single, compact, optimised executable file that can be run on the OS without the source code.

There are compilers for Python. Pypy is a just in time compiler that compiles and optimises code as it is run to speed it up. There are also compilers that compile python into java bytecode and C. Though usually python code was sped up by rewriting just the CPU intensive functions in compiled C.

These days on the internet complier and interpreter tend to be used interchangeably, as few people have done a proper CS degree and understand the nitty gritty bits of coding.