This is a preview

This playground version isn't public and is work in progress.

Python

Python

Checking the sample code

Looking at the syntax

Even if it is almost a line-by-line conversion of the same imperative-style solution we saw in the previous chapter, the syntax is quite different:

  • Whitespace matters! Blocks for loops and conditional statements are indented. There are no curly braces { } or semicolons ;.
  • Type system is dynamic.
  • [2:] Slicing is a powerful and efficient tool to process only some part of a datatype such as string or list.
  • Instead of the traditional if statement, here I show Python's ternary operator, which has an unusual order of arguments.

Other characteristics

  • Python is now over 30 years old, but it was quite at the sideline in popularity in its first half of existence. However, in the past decade its popularity grew tremendously, partly due to the mainstream emergence of data science.
  • Python is relatively easy to learn.
  • Using its high level abstractions and expressiveness, it takes less time to create a prototype solution than in most other languages.
  • One of its main strength lies in the huge selection of available libraries, especially for data science, machine learning and natural sciences. If you have finished a basic Python tutorial, you should definitely check out numpy, pandas, matplotlib, scipy, scikit-learn, pytorch, etc., just to name only a few of the most used ones.
  • It is well suited for REPL (Read–eval–print loop) usage: instead of writing the code separately, you can run Python commands line-by-line and immediately see the result using (for example) Jupyter notebook.
  • It is interpreted, so it is quite slow. Despite this, it is used in machine learning where speed DOES matter. The contradiction is resolved by the fact that most Python ML libraries are written in a fast compiled language such as C, so the time spent at the Python interpreter is only a fraction of the whole running time.

Resources to check

Coming next...

So far, we have seen some managed, some interpreted and some functional languages. Now let's change gears and see what speed a native compiler can bring. Entering the stage: C++... Nah, what did you think of, it will be Pascal, of course! :-)

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content