Programming language like COBOL, C, C++, Pascal or Photon concentrates more on the functional aspect of programming. In these languages there will be more focus on writing the code using functions, for example, we can imagine a C or C++ program as a combination of several functions.
Introduction to Python.
Python is a programming language that combined the future of C and JAVA. Python offers an elegant style of developing programs like C or C++. When programmers want to go for object-oriented programming then python offer classes and objects like Java. In Python, the program to add two numbers would be as follows:
# Example 1: Simple program to add two variables. #
a = 10 # Assign value to first variable.
b = 20 # Assign value to second variable.
# Display the sum.
print ("The Sum is =", (a + b))
The above code is simple and easy to understand and develop. In fact, code is very precise and do not need any explicit declaration of the variable.
Hence fight and is gaining the popularity among the programming folks. However, there are many such features that would certainly make python as one of the most popular and preferred programming languages in future.
History of Python.
Python was developed by Guido Va Rossum in the year 1991 at the centre for Mathematics and Computer Science managed by the Dutch Government.
Van Rossum was working on a project to develop system utilities in C where he had to interacts with the Bourne shell available in UNIX. He felt the need of developing a language that would very well bridge the gap between C programming language and the shell programming.
This gap eventually leads to the development of Python Programming Language.
How python got its name?
You’ll be surprised to know that Van Rossum picked the name for the new programming language from the TV show Monty Python’s Flying Circus. Python first working version was released by early 1990 and it was released for the public on Feb 20, 1991. The logo of Python shows two intertwined snakes as shown in the figure below:
A python is open-source software, which means anybody can freely download it from www.python.org and use it to develop programs. Its source code can be accessed and modified as per the requirements.
Feature of Python.
There are multiple reasons due to which python is gaining tremendous popularity in the programming community. The following are a couple of important features:
# Example - Dynamic type.
a = 10 # variable 'a' is treated as integer.
a = 'Topictrick' # variable 'a' is treated as string.
How Python compiler and Python interpreter works?
Let’s assume that we write a python program with the name calc.py. Here, calc is the program name and the .py is the extension name. All programs written in python has an extension name .py. After completing the program next step is to compile the program using the Python compiler.
The sequence of Python program compilation.
Program Source Code –> Byte Code –> Machine Code –> Program Output.
Python compiler actually translates program code into another code which is known as byte code. Byte code represents a fixed set of instruction that represents all operations like arithmetic operations, comparison operator, operations memory-related operations, etc. which run on an operating system and hardware.
Thus, byte code is a platform independent code and each instruction size is 1 byte. The corresponding byte code for our sample calc.py program would be calc.pyc.
Now, the next step is to run the is to run a program if you directly give the bite go to the computer it cannot execute them. Computers can only execute byte code which comprises 0s and 1s since the machine can only understand binary codes.
Thus, it is necessary to convert the byte code into binary code so that the computer can understand. Hence, Python Virtual Machine (PVM) actually translate byte code into Machine code.
Python Virtual Machine uses an interpreter to understand the byte code and converts it to machine code. PVM first understands the computer operating system and processor and then convert byte code into binary code. This machine code instruction is executed by the processor to generate output.
An interpreter translator program source code line by line. Hence, it is slow. The interpreter that is found inside the PVM run the Python program slowly. In order to rectify this problem, certain version of Python a compiler is added to the PVM. This compiler also converts the byte code into machine code but faster than interpreter this compiler is called JIT (Just In Time). The advantage of JIT (i.e. Just In Time) compiler is to improve the speed of execution of the Python program and does improve the performance.
Normally, when you compile a Python program, you cannot see calc.pyc and machine code because the entire process is done internally in the memory and final output is visible.
Note: JIT compiler is not available with all Python version.
What is PVM or Python Virtual Machine?
As you know that computer can only understand binary code (i.e. 0s or 1s). It’s mandatory that all high-level program should be converted into binary code before it is actually executed by a computer. Thus, every programming language is associated with a compiler that actually converts code into the desired machine code.
A python compiler does the same task but in a slightly different way. Python compiler actually converts source code into intermediate code i.e. Byte Code. Now, these byte codes need to convert into machine code and it is Python Virtual Machine that does this job.
The primary role of Python Virtual Machine is to convert Byte Code instruction into machine code so that it can be executed via computers. PVM is equipped with the interpreter, it actually translates byte code into machine code and sends machine code to process for execution. Python Virtual Machine is also known as an interpreter because playing the crucial role of converting and executing instructions.
Comparisons between C and Python?
Comparisons between Java and Python?
Conclusion.
Finally, python, as a programming language is becoming popular day by day and big companies, are now considering python for developing various tools and applications. Eventually, python would be a tough competitor for JAVA, .NET, C, COBOL etc. Although it has already acquired a big market and buzz is already created in IT industry.
Last but not the least, if you like our article then, please leave your feedback and share it with your friends. We would be publishing more such interesting Python tutorial.