Python Notes 2
Python Notes 2
What is
Python?----------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
Python is a widely-used, interpreted, object-oriented, and high-level programming
language with dynamic semantics, used for general-purpose programming.
The name of the Python programming language comes from an old BBC television comedy
sketch series called Monty Python's Flying Circus.
Python's creator named the language in honor of the TV show.
Who created
Python?----------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
One of the amazing features of Python is the fact that it is actually one person's
work.
New programming languages are developed and published by large companies employing
lots of experts, and due to copyright rules, it is very hard to name any of the
people in the project.
Python is an exception.
There are not many languages whose authors are known by name.
Python was created by Guido van Rossum, born in 1956 in Haarlem, the Netherlands.
Of course, Guido van Rossum did not develop and evolve all the Python components
himself.
The speed with which Python has spread around the world is a result of the
continuous work of thousands (very often anonymous) programmers, testers and users.
Many of them weren't IT specialists and enthusiasts, but it must be said that the
very first idea (the seed from which Python sprouted) came to one head, Guido's.
A hobby programming
project?---------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--
In December 1989, I was looking for a "hobby" programming project that would keep
me occupied during the week around Christmas.
My office would be closed, but I had a home computer, and not much else on my
hands.
I decided to write an interpreter for the new scripting language I had been
thinking about lately: a descendant of ABC that would appeal to Unix/C hackers.
I chose Python as a working title for the project
In 1999, Guido van Rossum defined his goals for Python.
An easy and intuitive language just as powerful as those of the major competitors
and open source, so anyone can contribute to its development.
Code that is as understandable as plain English and suitable for everyday tasks,
allowing for short development times.
About 20 years later, it is clear that all these intentions have been fulfilled.
Some sources say that Python is the most popular programming language in the world,
while others claim it's the second or the third.
Either way, it still occupies a high rank in the top ten of the PYPL PopularitY of
Programming Language and the TIOBE Programming Community Index.
Python isn't a young language anymore.
It is mature and trustworthy.
It's not a one-hit wonder.
It's a bright star in the programming firmament, and time spent learning Python is
a very good investment.
What makess Python so
special?---------------------------------------------------------------------------
-----------------------------------------------------------------------------------
How does it happen that programmers, young and old, experienced and novice, want to
use it?
How did it happen that large companies adopted Python and implemented their
flagship products using it?
There are many reasons we've listed some of them already, but let's enumerate them
again in a more practical manner.
It's easy to learn, the time needed to learn Python is shorter than for many other
languages; this means that it's possible to start the actual programming faster.
It's easy to teach, the teaching workload is smaller than that needed by other
languages.
This means that the teacher can put more emphasis on general (language-independent)
programming techniques, not losing energy on exotic tricks, WEIRD exceptions and
incomprehensible rules.
It's easy to use for writing new software, it's often possible to write code faster
when using Python.
It's easy to understand, it's also often easier to understand someone else's code
faster if it is written in Python.
It's easy to obtain, install and deploy, Python is free, open and multiplatform and
not all languages can boast that.
Python
Rivals?----------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
Python has two direct competitors, with comparable properties and predispositions.
Thes are: Perl – a scripting language originally authored by Larry Wall;
Ruby – a scripting language originally authored by Yukihiro Matsumoto.
The former is more traditional and more conservative than Python, and resembles
some of the old languages derived from the classic C programming language.
In contrast, the latter is more innovative and more full of fresh ideas than
Python.
Python itself lies somewhere between these two creations.
The Internet is full of forums with infinite discussions on the superiority of one
of these three over the others, should you wish to learn more about each of them.
Why not
Python?----------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
Despite Python's growing popularity, there are still some niches where Python is
absent, or is rarely seen.
Low-level programming (sometimes called "close to metal" programming).
If you want to implement an extremely effective driver or graphical engine, you
wouldn't use Python;
Applications for mobile devices although this territory is still waiting to be
conquered by Python, it will most likely happen someday.
Python
Implementations?-------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
The traditional implementation of Python, called CPython, is Guido van Rossum's
reference version of the Python computing language, and it's most often called just
"Python".
When you hear the name CPython, it's most probably used to distinguish it from
other, non-traditional, alternative implementations.
But, first things first.
There are the Pythons which are maintained by the people gathered around the PSF
(Python Software Foundation).
It is a community that aims to develop, improve, expand, and popularize Python and
its environment.
The PSF's president is Guido von Rossum himself, and for this reason, these Pythons
are called canonical.
They are also considered to be reference Pythons, as any other implementation of
the language should follow all standards established by the PSF.
Guido van Rossum used the "C" programming language to implement the very first
version of his language and this decision is still in force.
All Pythons coming from the PSF are written in the "C" language.
There are many reasons for this approach.
One of them is that thanks to it, Python may be easily ported and migrated to all
platforms with the ability to compile and run "C" language programs.
Virtually all platforms have this feature, which opens up many expansion
opportunities for Python.
This is why the PSF implementation is often referred to as CPython.
This is the most influential Python among all the Pythons in the world.
Cython?----------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
Cython is one of a possible number of solutions to the most painful of Python's
traits the lack of efficiency.
Large and complex mathematical calculations may be easily coded in Python.
Which is much easier than in "C" or any other traditional language, but the
resulting code execution may be extremely time-consuming.
How are these two contradictions reconciled?
One solution is to write your mathematical ideas using Python.
Then when you're absolutely sure that your code is correct and produces valid
results, you can translate it into "C". Certainly, "C" will run much faster than
pure Python.
This is what Cython is intended to do to automatically translate the Python code
(clean and clear, but not too swift) into "C" code (complicated and talkative, but
agile).
Jython?----------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
Another version of Python is called Jython.
"J" is for "Java". Imagine a Python written in Java instead of C.
This is useful, for example, if you develop large and complex systems written
entirely in Java and want to add some Python flexibility to them.
The traditional CPython may be difficult to integrate into such an environment, as
C and Java live in completely different worlds and don't share many common ideas.
Jython can communicate with existing Java infrastructure more effectively.
This is why some projects find it useful and necessary.
The current Jython implementation follows Python 2 standards.
There is no Jython conforming to Python 3, so far.
PyPy?------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
The PyPy logo is a rebus.
Can you solve it? It means: a Python within a Python.
In other words, it represents a Python environment written in Python-like language
named RPython (Restricted Python).
It is actually a subset of Python.
The source code of PyPy is not run in the interpretation manner, but is instead
translated into the C programming language and then executed separately.
This is useful because if you want to test any new feature that may or may not be
introduced into mainstream Python implementation, it's easier to check it with PyPy
than with CPython.
This is why PyPy is rather a tool for people developing Python than for the rest of
the users.
This doesn't make PyPy any less important or less serious than CPython, of course.
In addition, PyPy is compatible with the Python 3 language.
MicroPython?-----------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
MicroPython is an efficient open source software implementation of Python 3 that is
optimized to run on microcontrollers.
It includes a small subset of the Python Standard Library.
It is largely packed with a large number of features such as interactive prompt or
arbitrary precision integers, as well as modules that give the programmer access to
low-level hardware.
Originally created by Damien George, an Australian programmer, who in the year 2013
ran a successful campaign on Kickstarter.
He released the first MicroPython version with an STM32F4-powered development board
called pyboard.
In 2017, MicroPython was used to create CircuitPython, another one open source
programming language that runs on the microcontroller hardware.
It is a derivative of the MicroPython language.