Python programming language
Table of Contents
Introduction
Python programming language is high-level general-purpose language developed in 1991. Python can best be described as an object-oriented scripting language. It covers all important programming paradigms such as procedural, object-oriented and functional programming. It is considered a dynamic-typed language with automatic garbage collection. Python is in the top 10 programming languages for the last twenty years and was named Programming Language of the Year in 2007, 2010 and 2018. The philosophy behind the Python programming language is simplicity before complexity, as demonstrated by the syntax of the language itself, which is simple and readable.
Python actual versions
There are currently two active versions of Python: Python 2.x and 3.x. Python 2.x has been around for a long time and a lot of software is written in it, with wide user community. Python 3.x, as a successor to the old version, is taking on some primacy in the world of Python programming. Some differences are that Python 2.x writes strings in ASCII format while the newer version does it in Unicode. Python 3.x uses a brand new basic toolkit and library that is incompatible with the older version and so on. If you are new to programming and want to learn Python, it is advised to start with a newer version.
Advantages of Python
The benefits of Python crystallize immediately in its easy and readable code and general usage. Let’s look at some highlights:
- Readability, coherence, quality of software
- Used by best companies in the world
- A minimalist approach to problem solving
- The whole code makes up one third of the total code for C and C++
- More legible than most programming languages
- Dynamic high-level programming language
- Portable
- Large database of libraries of various uses
- Big developer community and support
- Easy to use and learn
Disadvantages of Python
Python programming language also has its drawbacks, focus is mainly on speed of Python runtime execution. Let’s look at the disadvantages:
• Slower in communication with hardware device and in use of large projects (because it uses an interpreter instead of a compiler)
• Not the first choice for mobile application programming
• Although Python has automatic garbage collection, it consumes more memory on large projects
• No advanced layer for database access
How Python runs program
Computer does not understand the source code and cannot execute it. Your computer understands 0 and 1 and needs to do some kind of conversion of your source code into a computer understandable language. There are two types of conversion of high-level source code to level code that is readable by processor: compiler and interpreter.
Before compiling the code, the compiler converts (compiles) code into computer readable format – object code. Object code is a low-level source code, i.e. a set of instructions for the processor. The advantage of a compiler is that once a program is compiled, it is executed multiple times without additional conversion.
On the other hand, the interpreter translates high-level source code in real time as the code is executed line by line. The result is a platform independent code that is saved in a file called byte code. The byte code is saved to a physical location on the disk with .pyc format and in __pycache folder. If there are no changes to the source code, Python byte code is used as a starting point to speed up the startup time.
If byte code conversion cannot be written to disk, Python writes to memory and deletes the memory location when exiting the program. It is important to note that byte code (.pyc) can be migrated to any platform on which Python is installed and run without the original .py file.
The final step in running Python is Python Virtual Machine (PVM). PVM is one big loop that goes through Python byte code and executes instructions.
Where Python is used?
Web development
Website development is one of the most common uses of the Python programming language. It uses one of the most popular web frameworks such as Django and Flask that includes authentication, management panels, datagram upload structure, templates, URL routing and much more.
Internet scripting
Wide range of features make Python among the first in this field: parsing HTML code XML and JSON files, creating, sending and parsing e-mails, communicating over sockets, XML-RPC, SOAP and much more.
Mathematics and science
Popular libraries such as NumPy and SciPy offer great opportunities for mathematicians and scientific in their daily work.
Machine learning
Very popular in this field, because of its simple and readable code and excellent data manipulation techniques.
System programming
System engineers use Python as the primary programming language for system automation. Python in this field offers search of files and directories, running other programs, parallel processing, regular expressions…
Data mining
Ideal for data mining due to its object-oriented nature, dynamic semantics, large developer community and code readability.
Who is using Python?
- Google uses Python for its web search algorithms as well as APP Engine.
- You Tube is mostly written in Python
- The Dropbox server and client part are mostly written in Python
- Maya – The Python scripting API is used in this popular 3D modeling software
- The NSA uses Python for cryptography
- NASA uses Python for scientific research
- Intel, Cisco and many others use Python for hardware testing
Python types
Python comes in many forms. Let’s take a look for most popular:
CPython
Standard Python that can be downloaded from www.python.org. Python compilation is done in C and C ++ program. It is so named because it is written in the ANSI C programming language.
JPython
This type of Python consisting of Java classes and compiled into Java byte code and later into Java Virtual Machine.
IronPython
Newest version of Python that integrates with the Microsoft .NET framework.
PyPy
It is also called CPython on steroids because it uses the same CPython framework but uses JIT (Just in Time compiler) that enhances the performance of a program runtime execution. According to some research, PyPy runs five times faster than standard CPython.