Chapter 2
What is Python?
2.1 Introduction to Python
Python is an open source and cross-platform programming language, that has
become increasingly popular over the last ten years. It was first released in
1991. Latest version is 3.7.0. CPython is the reference implementation of the
Python programming language. Written in C, CPython is the default and most
widely-used implementation of the language.
Python is a multi-purpose programming languages (due to its many extensions),
examples are scientific computing and calculations, simulations, web develop-
ment (using, e.g., the Django Web framework), etc.
Python Home Page [6]:
[Link]
The programming language is maintained and available from (Python Software
Foundation): [Link] Here you can download the basic Python
features in one package, which includes the Python programming language in-
terpreter, and a basic code editor, or an integrated development environment,
called IDLE. See Figure 2.1
But this is just the Python core, i.e. the interpreter a very basic editor, and the
minimum needed to create basic Python programs.
Typically you will need more features for solving your tasks. Then you can in-
stall and use separate Python packages created by third parties. These packages
need to be downloaded and installed separately (typically you use something
called PIP), or you choose to use, e.g., a distribution package like Anaconda.
Python is an object-oriented programming language (OOP), but you can use
Python in basic application without the need to know about or use the object-
oriented features in Python.
Python is an interpreted programming language, this means that as a developer
17
Figure 2.1: IDLE - Basic Python Editor
you write Python (.py) files in a text editor and then put those files into the
python interpreter to be executed. Depending on the Editor you are using, this
is either done automatically, or you need to do it manually.
Here are some important Python sources: [6], [7], [8].
2.1.1 Interpreted vs. Compiled
What are the differences between Interpreted programming languages and Com-
piled programming languages? What kind should you choose, and why should
you bother?
Programming languages generally fall into one of two categories: Compiled or
Interpreted. With a compiled language, code you enter is reduced to a set of
machine-specific instructions before being saved as an executable file.
Both approaches have their advantages and disadvantages.
18
With interpreted languages, the code is saved in the same format that you en-
tered. Compiled programs generally run faster than interpreted ones because
interpreted programs must be reduced to machine instructions at run-time. It
is usually easier to develop applications in an interpreted environment because
you don’t have to recompile your application each time you want to test a small
section.
Python is an interpreted programming language, while e.g., C/C++ are trans-
lated by running the source code through a compiler, i.e., C/C++ are compiled
languages.
Interpreted languages, in contrast, must be parsed, interpreted, and executed
each time the program is run.
Another example of an interpreted programming language is PHP, which is
mainly used to create dynamic web pages and web applications.
Compiled languages are all translated by running the source code through a
compiler. This results in very efficient code that can be executed any number of
times. The overhead for the translation is incurred just once, when the source
is compiled; thereafter, it need only be loaded and executed.
During the design of an application, you might need to decide whether to use a
compiled language or an interpreted language for the application source code.
Interpreted languages, in contrast, must be parsed, interpreted, and executed
each time the program is run
Thus, an interpreted language is generally more suited for doing ”ad hoc” cal-
culations or simulations, while compiled languages are better for permanent
applications where speed is in focus.
2.2 Python Packages
With Python you don’t get so much out of the box. Instead of having all of
its functionality built into its core, you need to install different packages for
different topics.
This approach has advantages and disadvantages. An disadvantage is that you
need to install these packages separately and then later import these modules
in your code.
This is also typical approach for open source software, because everybody can
create their own Python packages and distribute them. In that way you also
find Python packages for almost everything, from Scientific Computing to Web
Development.
19
These packages need to be downloaded and installed separately, or you choose
to use, e.g., a distribution package like Anaconda, where you typically get the
packages you need for scientific computing. With Anaconda you typically get
the same features as with MATLAB.
Lots of Python packages exists, depending on what you are going to solve.
We have Python packages for Desktop GUI Development, Database Develop-
ment, Web Development, Software Development, etc.
See an overview of Applications for Python:
[Link]
See also the Python Package Index (PyPI) web site:
[Link]
Here you can search for, download and install many hundreds Python Packages
within different topics and applications. You can also make your own Python
Packages and distribute them here.
2.2.1 Python Packages for Science and Numerical Com-
putations
Some important Python Packages for Science and Numerical Computations are:
• NumPy - NumPy is the fundamental package for scientific computing
with Python [9]
• SciPy - SciPy is a free and open-source Python library used for scientific
computing and technical computing. SciPy contains modules for optimiza-
tion, linear algebra, integration, interpolation, special functions, FFT, sig-
nal and image processing, ODE solvers and other tasks common in science
and engineering. [9]
• Matplotlib - Matplotlib is a Python 2D plotting library. [10]
• Pandas - Pandas Python Data Analysis Library [11]
These packages need to be downloaded and installed separately, or you choose
to use, e.g., a distribution package like Anaconda, where you typically get the
packages you need for scientific computing. With Anaconda you typically get
the same features as with MATLAB.
2.3 Anaconda
Anaconda is a distribution package, where you get Python compiler, Python
packages and the Spyder editor, all in one package.
Anaconda includes Python, the Jupyter Notebook, and other commonly used
packages for scientific computing and data science.
20
They offer a free version (Anaconda Distribution) and a paid version (Enter-
prise) Anaconda is available for Windows, macOS, and Linux
Web:
[Link]
Wikipedia:
[Link] P ythond istribution)
Spyder and the Python packages (NumPy, SciPy, Matplotlib, ...) mention above
+++ are included in the Anaconda Distribution.
2.4 Python Editors
An Editor is a program where you create your code (and where you can run
and test it). Most Editors have also features for Debugging. For simple Python
programs you can use the IDLE Editor, but for more advanced programs a bet-
ter editor is recommended.
Examples of Python Editors:
• Python IDLE
• Visual Studio Code
• Spyder
• Visual Studio
• PyCharm
• Wing Python IDE
• Jupyter Notebook
These editors are shortly described below and in more detail later in this text-
book.
Which editor you should use depends on your background, what kind of code
editors you have used previously, your programming skills, what your are going
to develop in Python, etc.
2.4.1 Python IDLE
The programming language is maintained and available from (Python Software
Foundation): [Link] Here you can download the basic Python
features in one package, which includes the Python programming language in-
terpreter, and a basic code editor, or an integrated development environment,
called IDLE. See Figure 2.1
Web:
[Link]
21
2.4.2 Visual Studio Code
Visual Studio Code is a source code editor developed by Microsoft for Windows,
Linux and macOS.
Web:
[Link]
Resources: Getting Started with Python in Visual Studio Code
2.4.3 Spyder
Spyder is an open source cross-platform integrated development environment
(IDE) for scientific programming in the Python language.
Web:
[Link]
Wikipedia:
[Link] sof tware)
Spyder is included in the Anaconda Distribution.
2.4.4 Visual Studio
Microsoft Visual Studio is an integrated development environment (IDE) from
Microsoft. It is used to develop computer programs, as well as websites, web
apps, web services and mobile apps. The deafult (main) programming language
in Visual studio is C, but many other programming languages are supported.
Visual studio is available for Windows and macOS.
Visual Studio (from 2017), has integrated support for Python, it is called
”Python Support in Visual Studio”.
Web:
[Link]
Wikipedia:
[Link] isualS tudio
2.4.5 PyCharm
PyCharm is cross-platform, with Windows, macOS and Linux versions. The
Community Edition is free to use, while the Professional Edition (paid version)
has some extra features.
22
Web:
[Link]
2.4.6 Wing Python IDE
The Wing Python IDE family of integrated development environments (IDEs)
from Wingware were created specifically for the Python programming language.
3 different version of Wing exists [12]:
• Wing 101 – a very simplified free version, for teaching beginning pro-
grammers
• Wing Personal – free version that omits some features, for students and
hobbyists
• Wing Pro – a full-featured commercial (paid) version, for professional
programmers
2.4.7 Jupyter Notebook
The Jupyter Notebook is an open-source web application that allows you to cre-
ate and share documents that contain live code, equations, visualizations and
text.
Web:
[Link]
Wikipedia:
[Link] upyter
2.5 Resources
Here are some useful Python resources:
• The official Python Tutorial
- [Link]
• The official Python Documentation
- [Link]
• Python Tutorial ([Link]) [13]
- [Link]
2.6 Installing Python
The Python programming language is maintained and available from (Python
Software Foundation):
23
[Link]
Here you can download the basic Python features in one package, which includes
the Python programming language interpreter, and a basic code editor, or an
integrated development environment, called IDLE. See Figure 2.1
For basic Python programming this is good enough.
For more advanced Python Programming you typically need a better Code Ed-
itor and additional Packages.
For the basic Python examples in the beginning, the basic Python software
from:
[Link] is good enough.
I suggest you start with the basic Python software in order to learn the basics,
then you can upgrade to a better Editor, install addition Python packages (either
manually or or install Anaconda where ”everything” is included).
2.6.1 Python Windows 10 Store App
Python 3.7 is also available in the Microsoft Store for Windows 10.
The Microsoft Store version of Python 3.7 is a simplified installer for running
scripts and packages.
Microsoft Store version of Python 3.7 is very basic but it’s good enough to run
the simple scripts.
Python 3.7 Microsoft Store edition will receive all updates automatically when
they are released and no manual action is required from your end.
In order to install the Microsoft Store version of Python just open Microsoft
Store in Windows 10 and search for Python.
2.6.2 Installing Anaconda
The Spyder Code Editor and the Python packages (such as NumPy, SciPy, mat-
plotlib, etc) are included in the Anaconda Distribution.
Download and install from:
[Link]
2.6.3 Installing Visual Studio Code
Visual Studio Code code is a simple and easy to use editor that can be used for
many different programming languages.
24
Download and install from:
[Link]
Getting Started with Python in Visual Studio Code:
[Link]
25