Blog

Follow our blog and get to know about the latest updates in the fields of technology like Python, Machine Learning, Data structures, Data Science, Digital Marketing etc.

How does Python work?

24.05.2021

Python – Definition?

According to Wikipedia “Python is an interpreted, high-level, general-purpose programming language. It is dynamically typed and garbage-collected.”

How did Python start?

Python was first released in 1991 and was started as a hobby project by Guido Van Rossum. The programming language in which Python is said to have succeeded is ABC Programming Language, which had the interfacing with the Amoeba Operating System and had the feature of exception handling. Earlier in his career, he had already helped to create ABC and had seen some issues with ABC but liked most of the features. He had taken the syntax of ABC, and some of its good features, along with that he fixed a lot of issues completely and had created a good scripting language that had removed all the flaws.

It’s a general-purpose language. Programmers are allowed to express concepts in fewer lines of code due to its easy syntax.

Due to its simplicity, top technology organizations like Dropbox, Hewlett-Packard, Qualcomm, Google, Quora, Mozilla, IBM, and Cisco have implemented Python.

Interpreted Language 

Python doesn’t convert its code into machine code that can be understood by hardware. It actually converts it into byte code. So within python, compilation occurs, but it’s just not into a machine language. It is into byte code and the CPU can’t understand this byte code. So an interpreter called the python virtual machine is required. The python virtual machine executes the byte codes.

That is why Python is called an interpreted language. It goes through an interpreter, which turns written code into the language that can be understood by the computer's processor, whereas in a compiled language, the target machine directly translates the program. 

Interpreted languages tend to be more flexible, and often offer features like dynamic typing and smaller program size. Also, because interpreters execute the source program code themselves, the code itself is platform independent.

Garbage collection

To understand the term garbage collection, we first need to understand what is memory management. A programming language uses objects in its programs to perform operations. Objects include both simple variables, like strings, integers, or booleans, and more complex data structures like lists, hashes, or classes. The values of the program’s objects are stored in memory for quick access.

In early programming languages, developers were responsible for all memory management in their programs, but with the introduction of automatic memory management, programmers no longer needed to manage memory themselves.

Garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim memory occupied by objects that are no longer in use by the program. Garbage Collector automatically frees up space without you doing anything. 

Following tasks are performed by the interpreter to execute a Python program

First, the interpreter reads a python code, then it verifies that the instruction is well-formatted, if it encounters any error, it immediately halts the translation and shows an error message.

If there are no errors, that means the python instruction or code is well-formatted. Then the code is translated into its equivalent form in an intermediate language called “Byte code” by interpreter.

Post successful execution of Python script or code, it is completely translated into Byte code.

Byte code is sent to the Python Virtual Machine(PVM)- the interpreter. Here again, the byte code is executed on PVM. If an error occurs during this execution then the execution is halted with an error message.

Get started with Python

You can download and install it from the Python site for free. If you don't want to install the software on the computer, you can use a free tool, Google Colaboratory, which allows you to write and run Python code in your web browser.

There are free and paid online courses you can take, but you don't have to spend a fortune to learn this. The best way to learn any programming language is by doing, so after learning the basics choose a project you are passionate about and start building it.