What is Python and what is it used for

by Alex
What is Python and what is it used for

Python is a high-level programming language that is used in various areas of IT, such as machine learning, application development, web development, parsing, and others. In 2019, Python became the most popular programming language, overtaking Java by 10%. There are many reasons for this, one of which is the high pay for skilled professionals (about $100,000 per year).

Python programming language

Different programming languages usually dominate some industry (or several) for which they are well suited. But that doesn’t mean that a programmer is restricted to using a strictly specific tool, so any general-purpose language like Python can be used to create anything. Python has been able to capture a small part of the web development market, is sometimes used to write desktop applications, and of course, dominates machine learning completely. It’s also used to create a lot of prototypes that allow you to quickly sketch out the functionality and look and feel of a future project.

Origin of the name

The author of the Python language named it after the British comedy show “Monty Python,” which was popular in the early 1970s. This TV show allowed the author to relax and distract from language development. However, despite the real origin of the name, it is more obvious for people to associate Python with the word “snake. The logo, which depicts a reptile, also contributes to this. Although the creator of the language has repeatedly said that the name has nothing to do with snakes, it has failed to sway public opinion.

Python or Python?

Whether it’s the name of a British TV show or the English sound of the word “snake,” Python is correctly pronounced as Python. However, about 80% of the Russian community is accustomed to using the word “Python. It is impossible to say that it is uniquely correct to use one of the options, many names are adapted to the pronunciation of a particular language, and to change the established habits of society is very difficult. However, the variant of the name “Python” is appropriate to use only in a conversation with the Russian-speaking interlocutors, because at any international conference the meaning of the word “Python” simply would not understand, because in English there is only “Python (Python).

Logo

The logo shows two snakes forming a square with a convex center, this often misleads users, forcing them to associate the name of the language with the reptile. The logo was created by the author’s brother, Joost van Rossum, a programmer and typographic designer. He developed both the logo design (the two snakes) and the Flux Regular text font.

What is Python and what is it used for

Creation history

The language began to be developed by the programmer, Guido van Rossum, in the late 1980s. At that time he was working at a mathematics and computer science center in the Netherlands. Guido van Rossum has been interested in working with “iron” since he was in school, and although he didn’t find the support and approval of his peers, that didn’t stop him from developing a programming language himself. Rossum worked on Python in his spare time, using as a base the ABC programming language he had once helped develop. Stages in the history of the Python programming language:

  • In February 1991 the source code of the language was published on alt.sources. Even then the language had an object-oriented approach, and could handle classes, inheritance, functions, exception handling, and all basic data structures.
  • In 2000,the second version of Python was released. It added many important tools, including Unicode support and a garbage collector.
  • on December 3, 2008, a third version of Python was released and is still the main language today. Many features of the language were redesigned and became incompatible with previous versions. And although the functionality of the third version is not inferior to the second version, the development of the language was divided into two branches. Some continued to use Python 2 to support older projects, while others completely switched to version 3.

The death date for version 2 was set for 2015, but fearing not to have time to migrate all existing code to Python 3, Python 2’s lifespan was extended to 2020.

Python is a simple language

Python’s syntax has always set it apart from other programming languages. It does not suffer from redundancy, the similarity of the syntax to plain English allows even the average user to understand the code, in addition, the programmer writes fewer lines of code because there is no need to use the characters: “;”, “{“, “}”. Nesting is indicated by indentation, which increases the readability of the code and teaches newcomers to the proper design.

The simplicity is partly due to the fact that Python is written based on the ABC language, which was used to teach programming and the everyday work of people who are not programmers.

Python simplifies code writing and makes development fast, all because it has the following features:

  • Dynamic typing. The programmer doesn’t need to specify the type of variables; the language will assign it itself. Operands of different types, involved in one operation are automatically converted to the right one by certain rules.
  • It is convenient to return multiple values with a function. You can list them separated by commas and they are automatically converted to a list. To return an array from the function, just write “return_array_name“. There is no need to allocate memory and pass pointers to the function.
  • Automatic allocation of memory. The programmer doesn’t have to allocate memory for anything by himself. On the one hand, it reduces the programmer’s control over the program, on the other hand, development is much faster.
  • Garbage collector. If an object becomes useless (no longer referenced), it is automatically removed by the garbage collector. Garbage collector allows the optimized use of memory and not to delete useless objects manually.
  • a, b = b, a. This line reverses variable values, so that what was in a is now in b and vice versa. This is possible because Python first looks at the variables to the right of the “=” sign and puts them into a list, then it does the same with the items to the left of the “=” sign and then it links each item of the right list to the left. In this way, you can exchange the values of not only two variables, but also three, five, and so on.
  • Data type binding. The data type is bound to a value, not a variable. That is, a value is an object with attributes that determine its type and other characteristics, and a variable is just a reference to this object. This approach allowed us to avoid explicit type definitions and greatly simplified the re-assignment of a value to a variable (especially if the type of the new value is different from the original one).
  • The for loop. Working with arrays, lists and other containers in Python is easy and convenient. When you want to search all of its elements, the construction looks like this: “for x in container:” (the search goes from 0 to the last element, its index can be designated as -1). If it needs to go through a certain number of cycles, they write it like this: “for x in range(1,9):” (the loop will be executed with the values of x from 1 to 8).
  • Interpretable language. You don’t need to compile the written code, just run it and get the result. Moreover, you can work interactively and get the result literally after each operation.
Python combines both simplicity and powerful tools. It can be used to prototype almost any program.

To speed up development, a part of the program (usually not much of a speed bump) is written in Python. The simplicity of this programming language has allowed it to dominate the field of machine learning. People somehow connected with science prefer not to spend a lot of time on such things as writing code, so Python is perfectly suited to their tasks. Example code:

def what_bigger(a, b):
    if a > b:
        print(a, "more than", b)
    else:
        print(b, "more than", a)
def max_arr(arr):
    max = 0
    for x in arr:
        if arr[x-1] > max:
            max = arr[x]
    return max
def arr_to_2arr(array):
   array = array * 2
   return array
print("A simple Python program")
a = [1,2,3,6,1,6]
what_bigger(1,5)
r1 = max_arr(a)
r2 = arr_to_2arr(a)
print("Return function max_arr - ", r1)
print("Return function arr_to_2arr - ", r2)

Execution results:

A simple Python program
5 is greater than 1
Return function max_arr - 6
Return function arr_to_2arr - [1, 2, 3, 6, 1, 6, 1, 2, 3, 6, 1, 6]

Popularity

Despite being over 29 years old, the language is popular with programmers all over the world. Python is used in almost every medium or large project, if not as the main development tool, then as a tool for prototyping or writing some part of it. It has gathered a huge community of developers around it, with Python ranked 7th in a Stackoverflow poll with almost 39% of the vote.

TIOBE Index

This index shows the popularity of programming languages, the information is updated every month. The popularity rating is based on the number of qualified professionals worldwide. All popular search engines are also used for the analysis. It is important to understand that the index does not show the best programming language, it only shows their popularity.

TIOBE IndexAccording to the TIOBE index, Python ranked 3rd with 9% popularity. It was second only to Java and C.

PYPL

This index is based on the number of search queries related to learning materials for the language.

PYPLAccording to data from the PYPL, Python ranks first with more than 29% popularity and is 10% ahead of Java.

statista.com

The service provides various kinds of statistics, among which is the popularity of programming languages.

statista.comAccording to a survey of more than 85,000 respondents, Python ranks 4th, behind such languages as JS, markup languages and SQL.

Speed

Programmers often ask the question, “Will using Python lead to performance degradation?” Don’t draw any conclusions without a detailed investigation. If you consider only code execution speed, it is clear that Python is inferior to other programming languages such as C. Indeed, dynamic typing, interpretability, and other features that make the programmer’s job easier lead to performance degradation.

However, in today’s IT, it is not only the speed of programs that matters, but also the speed of their development. Development, testing, debugging, and support all cost a lot of money. And while Python is inferior in speed of programs, it has no equal in speed of development.

For any project, it is important to choose the right tool and the best implementation. Improving one, the programmer sacrifices the other, his task is to find the perfect balance, focusing on a particular technical specification. Python allows you to write fairly fast code, but can fail in some of the “bottlenecks”, which have the greatest impact on the performance of the project. In order not to delay the development and get the output of the program running at high speed, its structure is designed so that the ratio “performance / development time” was the maximum. Programmers use techniques to compensate for the lack of speed in Pyton:

  • Embedding C code. This method can help to considerably increase the productivity. Usually C is used for writing code fragments which process a lot of requests per unit time. For example, a function that receives data from one database, processes it and sends to another is better written in C if the amount of passing information is large enough.
  • Using the best algorithms and tools. The same task can be solved in different ways. First, the programmer must choose the most efficient algorithm that provides the best performance, for example, to find an element in a sorted array, you can search from beginning to end, in the best case (element at the beginning of the array) search will be fast, in the worst case (the element at the end of the array) – slow. It is more effective to use the method of dividing in half (binary search), which will find the required element for the minimum number of iterations in the array of any length. Secondly, you need to choose the right tools for the task. For example, if the sequence of elements is strictly defined and does not change, it is better to use a tuple rather than a list. It requires less space, is faster to process, and is protected against accidental changes.
  • Interpreter optimization. The speed of Python programs is highly dependent on how the interpreter works, some constructs are faster and others are slower.
    Faster Slower
    a, b = c, d a = c; b = d
    a < b < c a < b and b < c
    not a bool(a)
    a = 5 a = 2 + 3
    code embedded in the loop function call with code in a loop
  • Modules for testing. To determine which parts of the code severely reduce the overall performance, the programmer can use special testing modules. This way it’s possible to understand what code must be optimized or replaced with C code.
  • Ready-made tools. Efficient solutions have already been developed for most tasks. It’s better to use a ready-made, well-established code of some library than write your own solution from scratch, which will be 100% not so effective.

What you can write in Python

Python is used in many areas of programming, so anything can be written in it.

Back-end site

For back-enddevelopment, the frameworks used are Django and Flask. They turn Python into a server-side programming language with the same capabilities as other popular tools. The programmer can easily work with URL links, database calls and creation of HTML files which the user sees in the browser. And while PHP controls most of the web server development market, more and more programmers prefer to develop in Python.

Blockchain

Blockchain is a sequential chain of blocks, where each block contains information and is always linked to the previous block. The technology can be used in any sphere and is especially popular in the financial sphere and bitcoin cryptocurrency. Blockchain combines the security and openness of information, it allows you to access data from anywhere in the world, at the same time it is almost impossible to hack, the data is stored on some master computer, and it is very expensive and time consuming to hack each block. You can write a full-fledged blockchain in Python with no problem, if it’s intelligently designed, it will keep up with the performance of other language solutions.

Bot

A bot is a program that automatically does something at a given time or in response to a signal. Bots can primitively simulate human behavior, so they are often used for technical support work (chatbots), searching for information on the Internet (search bots), imitating the actions of a person or other creature in the virtual world (computer games). Python allows you to quickly create feature-rich and relatively smart bots. It is important to understand that bots are not a simple program of 500 lines of code. It can cost several million to order to create a bot for a business. The price is due to the fact that it is very difficult to design a bot that will be difficult to distinguish from a human. It is necessary to provide for many variants of dialogs, analyze the behavioral factors of a person and implement them in the program. Simply put, you have to make a primitive “brain” out of a machine that understands only zeros and ones.

Database

A database is information systematized according to general attributes and special rules. In any large project, databases are used to store information about users, program changes, etc. A database management system can be written in Python.

Augmented reality

Augmented reality supplements the physical world with virtual technology. That is, virtual objects are projected onto a real environment, and mimic the features and behavior of ordinary physical objects. Augmented reality can be seen in movies, such as Iron Man. In the real world, it is used, for example, in combat fighters (targeting system). The work of augmented reality is based on interaction with tags. The electronic device receives information and analyzes the surrounding space, with the help of computer vision it “understands” what the person sees in front of him. The device then superimposes a “virtual layer” on the real world. Professional augmented reality applications cost about half a million rubles, it is not easy to design and write them, various specialists are involved in the development process, from 3D designers to programmers. Python is a great tool to create augmented reality projects.

BitTorrent Client

BitTorrent is a unique technology that allows you to quickly exchange large volumes of data over the Internet. Until version 6, the BitTorrent client was written entirely in Python. Although it was later completely rewritten in C++, it shows that Pyton can be used for this kind of tasks.

Neural Network

The concept of a neural network came to programming from biology. In biology a neural network is a sequence of neurons connected to each other. Programmatically created neural networks are capable not only of analyzing and memorizing information, but also of reproducing it from memory. They are used to solve complex problems where calculations are needed that are done by the human brain. Usually neural networks are used to classify something by features, to predict, to recognize, for example, a person from a photo or video.

Python is the clear leader in neural network development. In addition to standard tools, it has a huge number of libraries for machine learning. Thanks to this, Python can be written relatively quickly, even a large and complex project.

Parser

This software is for collecting and processing information. You can parse information such as the dollar exchange rate, or you can track and analyze changes in shares of different companies. Parser can be written in many languages, Python is not the only good tool for this, but its capabilities are enough to write an application that collects information quickly and efficiently.

Calculator

This task has probably been done by every computer science student. A calculator can be written in any programming language, and Python is no exception. It is important to understand that the calculator is required to be 100% accurate. Therefore, all errors related to rounding and binary representation of numbers can be critical. However, libraries have been written for Python that completely solve this problem.

The game

Large games are not created in Python, it is either used to develop a prototype, or to implement some part (such as server logic game or modding system).

To write a small project, you can use the library Pygame, which gives all the necessary tools to create a small 2D game.

Text Editor

It can be used to write and edit not only text, but code. Many text editors are able to detect the programming language used and highlight its syntax. Some of them even resemble a full-fledged IDE. Writing a small text editor is not difficult, but to create a large project will require a lot of knowledge and effort. Despite the speed of development in Python, creating a text editor with sufficient for the modern standards of functionality – the work for a team of programmers.

Programming Language

A computer is always a layered device. Using the most complicated and inconvenient tool, the programmer creates a simpler one, and from it, an even simpler one. Although this reduces productivity (if everything was written in assembler, the programs would run tens or even hundreds of times faster), it also greatly reduces the development time, its convenience and complexity. Python is a fairly high-level language, so it is not a good idea to write another programming language based on it, although you can. It would be more useful to develop an interpreter for the Python itself or another programming language. It is also possible to create a compiler (a program that converts the code of a programming language to machine code). Such projects are not suitable for commercial purposes, but creating your own compiler, interpreter, or language will provide much invaluable experience.

Related Posts

LEAVE A COMMENT