Python, the language with which you can do everything

Brief history

Although the name reminds us of a python, the name of this language is not given by this reptile, but by the name of the humorous group Monty Python of which the creator is fan. Python is a programming language originated in the late 80’s by Van Rossum and developed for the Amoeba operating system. In 1991 the code version 0.9.0 was published, which already included classes with the use of exceptions, capable of inheriting functions and including some modular types such as list, dict and str.

In 1994 this language included in its version 1.0 features such as some functional programming functions: reduce, filter, lamda and map. For Python version 2.0, compression lists were included based on Haskell’s syntax. Also with this version a garbage collection system was included.

In addition, the unification of types and classes within the same hierarchy was the biggest innovation in version 2.2, which made the object model robust and pure. Inspired by the Icon language, generators were also added.

As of January 1st, 2020, Python 2 (2.7.*) was officially discontinued, supporting only versions >=3.5.

Features 

This language is interpreted, which makes it offer portability between systems, although in specific situations the O.S. must be taken into consideration (in many of these cases in Windows).

As for its programming paradigm, Python is a multiparadigm language. Developers are not forced to use a specific style in their programming. Currently it has as paradigm styles: imperative, functional and object oriented programming. With the use of extensions, other paradigms can be supported. For memory management, dynamic typing and reference counting are used.

Another important feature is the dynamic linking of methods. This feature links a method and a variable name during the execution of the script.

In terms of syntax, Python was designed to have easy and clear readability, that’s why words are used instead of operators ( |, &, ! -> or, and, not) and indents are used instead of “{}”. Using the tabs, the code is structured and leveled according to the instructions. For example, the fibonacci function would be

def fib(n):
    a, b = 0,1
    while a < n:
        print(a, end=' ')
        a, b = b, a+b
    print()
fib(1000)
print()
fib(1000)

Because of the indentation, each sequence must be written in a single line, but if for problems of legibility you want to divide the sequence in more lines you can add one “\” at the end of each line to indicate that it continues in the next one.

capitales =["New York","Londres","Bogotá","Pekín",\
     "Tokio","París","Madrid","Lisboa"\
     “Antananarivo","Moscú"]"
print(f"Some capitals: {capitales}”)
out: Some capitals: ['New York', 'Londres', 'Bogotá', 'Pekín', 'Tokio', 'París', 'Madrid', 'Lisboa','Antananarivo', ‘Moscú']
duch_alba_name ="María del Rosario Cayetana Paloma Alfonsa "\
	"Victoria Eugenia Fernanda Teresa Francisca de Paula Lourdes "\
	"Antonia Josefa Fausta Rita Castor Dorotea Santa Esperanza"\
	"Fitz-James Stuart y de Silva Falcó y Gurtubay"

print(f"Duchess of Alba's name: {duch_alba_name}")
out: Duchess of Alba's name: María del Rosario Cayetana Paloma Alfonsa Victoria Eugenia Fernanda Teresa Francisca de Paula Lourdes Antonia Josefa Fausta Rita Castor Dorotea Santa Esperanza Fitz-James Stuart y de Silva Falcó y Gurtubay

Philosophy

In order to empathize with developers and create guidelines for creating correct code according to Python, in version 2.1.2 a class of Easter egg was added when importing the “this” package.

import this

When you run the above line from the interpreter, the famous Python Zen is printed on the console, whose rules, introduced by Tim peters, are as follows:

  1. Beautiful is better than ugly.
  2. Explicit is better than implicit.
  3. Simple is better than complex.
  4. Complex is better than complicated.
  5. Flat is better than nested.
  6. Sparse is better than dense.
  7. Readability counts.
  8. Special cases aren’t special enough to break the rules.
  9. Although practicality beats purity.
  10. Errors should never pass silently.
  11. Unless explicitly silenced.
  12. In the face of ambiguity, refuse the temptation to guess.
  13. There should be one– and preferably only one –obvious way to do it.
  14. Although that way may not be obvious at first unless you’re Dutch.
  15. Now is better than never.
  16. Although never is often better than *right* now.
  17. If the implementation is hard to explain, it’s a bad idea.
  18. If the implementation is easy to explain, it may be a good idea.
  19. Namespaces are one honking great idea — let’s do more of those!

With these rules it is intended that the programmer creates a simple, efficient, readable and easy to debug code following the python philosophy.

Growing

In the last years, the growth of Python use has positioned it in the number 2 of the ranking of the most used languages at a global level according to Github (graph extracted from the analysis of github octoverso). And in the following table (github) we can see the activity of the GitHub repositories of Python. Currently being 17% of all github changes.

Python, the language with which you can do everything 1 - python ranking
Python, the language with which you can do everything 2 - Captura de pantalla 2020 02 29 a las 2.00.33

This growth in its use is due to the great efficiency and scalability offered by the code, so it is being used in multiple disciplines. The applications that are using this language are several, but we will now explain the most used ones.

Python for Data Science and Big Data

Extracting and analyzing data in Python is a quick and easy task. That is why it is being used in the analysis of data from large companies to improve their performance from the data collected and to predict results. The easy manipulation of operations with equations and matrices make python a perfect substitute for languages like Matlab or Scilab. For to give a more “friendly” interface for those used to statistical languages like R, Python use the Anaconda framework which is often used together with Spider and Jupyter Notebook with which mathematicians feel more comfortable.

Some of the most used libraries for big data : Pyspark, Dask and Pydoop.

The most used libraries for data analysis and processing: Numpy, Pandas, Plotly , Matplot and Seaborn.

Python for the Web (Front-End)

Although the king of the web is php along with environments like Laravel, the language of Python allows you to write applications of all kinds with fewer lines of code. As for the best frameworks for the development of Front-End we find:

Django. It is the most complete web framework written in Python. It provides a fast and clean development in the creation of web pages. These pages can use CMS content management systems for modular programming of the websites, which facilitates the creation of robust and block-modeled websites. Some disadvantages of Django are that although the websites developed are more advanced than with other web frameworks, it is a rather slow framework compared to the others.

Pyramid. This is due to the merger of the Pylons 1.0 and repoze.bfg frameworks. This web development package is categorized by having a quick start, easy development for API’s work, and the possibility to include managers like CMS and KMS

Bottle. Widely used for the development of loT applications. It develops quite simple pages, but it is a very flexible manager when incorporating new libraries.

Flask. The most agile of the most used frameworks for web development. It was born as a joke for the day of the innocents, but has grown to position itself in such a way that it can be used in services such as Amazon (Lamda) and Google in its Cloud RUN. Flask by itself is very simple, but you can add modules like Jinja2 and SQLAlchemy to make it complete. There are all kinds of packages developed to create safe, robust and easy websites.

Python for scripting

Python is a language that allows the creation and execution of scripts with few lines of code. Among the use of scripting in this language, we can highlight scraping (obtaining data from websites) and the automation of tasks for server maintenance, image and sound editing…That is, with python you can easily schedule any task on your server.

When automated processes are combined for website content extraction, the term “bot” is used. A bot can be programmed to do a certain task (it can pretend to be a person) every certain time or at a programmed time.

The most libraries user for scrapping are Beautiful Soup, Scrapy, Selenium and Helium. The last two allow the control of Chrome and Firefox browsers in order to simulate the interaction of a real user. With this technique you can download web information such as text, images or sounds.

Python for Artificial Intelligence

The Python IA community is the largest in existence compared to other environments. There are many libraries developed for the deep learning and neural networking approach, so it is currently the most widely used language in Machine Learnig practices. Libraries like PyTorch (developed by Facebook), TensorFlow (developed by Google) and Keras are used.

Neural networks are created for the accomplishment of tasks avoiding that it is a process programmed like a script and if it is something more similar to the operation of the learning of the humans.
For example, with OpenCV , you can detect objects, faces, people, animals and all kinds of objects by making the network itself learn to distinguish specific objects in images. In addition, with this environment it is possible to develop an artificial intelligence capable of describing the context of images Vision AI.

Some of the most influential companies in this sector are Open AI, Google and Facebook.

Python para Backend, Webhook y API Rest

Any of the frameworks used for web can be used for the Backend, Webhook and Rest API since Python runs on the server. But in this case we are going to name other of the Frameworks that are used. It should be explained that in a Rest API service (e.g.: obtain data from db) the user’s request must be processed and returned in the shortest time possible, while in the Webhook (e.g.: upload an image to extract text) the response may take time to arrive since the image must be processed. With the following frameworks you can create the backend of any web or mobile application such as a rest Api for a Flutter application.

Japronto. This framework was developed to be the fastest service and the one that can process more requests in less time. With benchmark scores of being able to process and answer more than 1M requests per second, Japronto becomes the fastest Python framework being faster than Go and NodeJS. It is written using the C api. It is currently in Alpha status and its own creator recommends using Sanic.

Falcon. After Japronto, Falcon is the fastest API framework available. It is fast, minimalist and perfect for backend tasks, microservices and API’s. This project is still under development and has very interesting libraries that allow to create secure connections between client-server. It has the ability to incorporate asynchronicity through other libraries. With the implementation of PyPy it is able to process more than 300K req/sec

Sanic. Sanic is a web server development framework famous for being asynchronous. It is constantly updated and has stable versions. It can process more than 36K req/sec

Code speed

Python is not really fast in its execution, which makes bad comparisons with other languages like Go (Golang). To make a fair comparison, you should compare it with other systems that are also interpreted. In the case of Go it is compiled, which gives it a lot of advantage in the execution time. To avoid speed problems, other types of performers such as Cython and PyPy have been developed that give it an admirable speed of execution. In addition, there are libraries that help restructure the code so that it can be interpreted more quickly.

Conclusion

As a conclusion, we can see that the Python code structure allows this language to offer the execution of almost any task in a few lines of code. This language proves to be an all-rounder in the industry being able to do everything from bots that download data from other sites to complex neural networks that detect breast tumors in X-rays.

Leave a Comment