Lesson 2
Lesson 2
You will also learn how to install and configure the Python language. Finally, we
will be testing the installed Python.
LESSON PROPER
What is Python?
Python was written by Guido van Rossum as a hobby project, starting in December 1989.
It was fully functional on Feb. 20, 1991, and was made generally available—as open-
source—in 1992. Rossum chose the name Python because of his appreciation of a BBC
television comedy series called Monty Python’s Flying Circus. The creators of that show
toyed with other titles including Owl Stretching Time and The Toad Elevating Moment.
Had they settled on one of those, who knows what Python might have been called.
Python was designed with simplicity in mind. Rossum wanted the code to be English-like
and easy to read, write, and understand. The syntax is simple and approachable for
beginners, and seasoned programmers can come to Python from other languages
without any struggle.
Python is an interpreted language. You write your program source code into files, and the
Python interpreter reads the files and executes the commands you’ve entered. Compiled
languages such as C require additional steps between writing the program and running
the program.
A piece of software called a compiler reads the program files and generates a binary file
containing the low-level instructions that the computer understands. In other words, it
takes what you’ve written—the C source code—and creates a copy of it that has been
translated into the computer’s native tongue. With a compiled program, it’s the output
from the compiler—the binary file—that is executed.
The advantage of a compiled program is that they execute faster than an interpreted
program because the code doesn’t need to be interpreted every time it is run. But the
advantage of interpreted languages is the absence of the compiling step. And
compilation can be time-consuming. With Python, you can change a few lines of code
and instantly run your program.
2. Python has bridges to MATLAB or Octave. Python can install the MATLAB Engine
API so that Python programs can call MATLAB as a computational engine.
MATLAB programs can also call Python functions with some limitations. Some
distributions of Python may use Python packages such as Pymatbridge, which
can support both MATLAB and Octave and allows the use of MATLAB within
Jupyter Notebooks.
4. Python has very good input/output (I/O) options. Until recently, Fortran I/O has
traditionally been records based. In contrast, Python has long supported
multiple options for I/O and many additional packages to support all types of
I/O formats, including real-time and streaming formats.
5. Python has strong support for task automation. Python’s built-in scripting
features and multiple packages have strong support for task automation.
Automation of repetitive tasks and performing data logging are easy and takes
little effort.
6. Python can use a web front end. Python packages such as Django and Flask
make it possible to develop and use Python as an API with a web front end. This
functionality is particularly useful when using a cloud-based infrastructure as a
platform to access high-performance computing (HPC) back ends.
Returning to the crux of the matter, let’s focus on how these basic strengths become
more pragmatic reasons to adopt Python for scientific computing. The biggest driver for
using Python in scientific computing is the evolution of problem-solving approaches.
Installing Python
Installing and using Python is very simple. The installation procedure involves just three
steps:
check the Add Python 3.7 to path check box to include the interpreter in the
execution path.
4. Documentation
5. pip
6. tcl/tk and IDLE (to install
tkinter and IDLE)
7. Python test suite (to
install the standard library
test suite of Python)
8. Install the global launcher
for `.py` files. This makes
it easier to start Python
9. Install for all users.
Click Next.
11. Once the installation is over, you will see a Python Setup Successful window.
The last (optional) step in the installation process is to add Python Path to the System
Environment variables. This step is done to access Python through the command line. In
case you have added Python to environment variables while setting the Advanced
options during the installation procedure, you can avoid this step. Else, this step is done
manually as follows.
In the Start menu, search for “advanced system settings”. Select “View advanced
system settings”. In the “System Properties” window, click on the “Advanced” tab and
then click on the “Environment Variables” button.
Locate the Python installation directory on your system. If you followed the steps exactly
as above, python will be installed in below locations:
The folder name may be different from “Python37-32” if you installed a different version.
Look for a folder whose name starts with Python.
You have now successfully installed Python 3.7.3 on Windows 10. You can verify if the
Python installation is successful either through the command line or through the IDLE
app that gets installed along with the installation.
Search for the command prompt and type “python”. You can see that Python 3.7.3 is
successfully installed.
An alternate way to reach python is to search for “Python” in the start menu and clicking
on IDLE (Python 3.7 64-bit). You can start coding in Python using the Integrated
Development Environment (IDLE).
Hurray! You are ready to start developing Python applications in your Windows 10
system.
SUMMARY
A complier is a piece of software that reads the program files and generates a binary
file containing the low-level instructions that the computer understands.
SELF-LEARNING ASSESSMENT
Let us see how much you have learned from this lesson.
Answer the following questions.
TEST 1. Essay: Based on your understanding, discuss the following items using your own
words. Each item is 10 points.
1. Explain three reasons why Python is suitable for use in computational science.
ENRICHMENT ACTIVITY