Python Programming from First Principles: Learn to Code, Think Computationally, and Solve Real-World Problems
PDFEPUB
CHAPTER GUIDE · GETTING STARTED

What is Python?

On this pageWhat is programming?Why programming languages are neededWhy Python?A first glimpse of PythonPython versionsPreparing to run Python

Python is a programming language: a way to express instructions that a computer can execute. It allows us to begin with small programs and develop more complex solutions as our understanding grows.

What is programming?

Programming means describing a task precisely enough for a computer to carry it out. To put historical events in order, for example, a program needs a representation of each event, a rule for ordering the events and instructions for displaying them.

The programmer defines those choices and checks the result. A computer can follow instructions quickly, but speed does not guarantee that the instructions solve the intended problem.

Why programming languages are needed

Processors operate on machine instructions represented in binary. A programming language lets us describe a computation using meaningful names and operations instead of writing those instructions directly.

We write source code in Python. A Python implementation handles that code, and its interpreter executes the program. This gives us a readable way to express a solution while the implementation manages the lower-level work. Readability still depends on precision: Python’s punctuation and structure have defined meanings.

Why Python?

Several features make Python a useful starting point for the work in this book:

  • Readable notation. Meaningful names and a consistent structure help reveal what a program does.
  • A gradual starting point. A short program can use only a few language features; more can be introduced as the problem requires them.
  • A range of applications. Python supports automation, data analysis, web applications and machine learning.
  • Libraries and learning resources. Existing packages extend the language, while documentation and community resources help answer unfamiliar questions.

The examples here begin with greetings and historical timelines before developing the ideas needed to work with data and more complex programs.

A first glimpse of Python

This short example records a historical event and displays it:

year = 1969
event = "First humans land on the Moon"
print(year, event)
Listing 1 — Naming two values and displaying a historical event.

Three parts are worth noticing:

  • Names: year and event refer to information used by the program.
  • Values: 1969 is a number; the words inside quotation marks are text.
  • Output: print() displays the two values in the order given.

The result is:

1969 First humans land on the Moon
Listing 2 — Output from the historical-event example.

Variables, text and the print() function will be explained more fully in the following chapters. For now, the example shows how a few readable instructions produce a visible result.

Python versions

  • Python 3 is the version family used throughout this book. The Python Developer’s Guide1 lists the releases that are currently supported.
  • Python 2 is an earlier, incompatible generation. Its official support ended on 1 January 20202, and it is not used here.

In a version number such as 3.14.3, the numbers identify the major version, feature release and maintenance release. The introductory examples do not require the exact version shown in a screenshot; they require a supported Python 3 release compatible with the chosen tools.

Preparing to run Python

The next step is to make Python available on the computer. Installing Python establishes the working environment in which these instructions can be saved, executed and examined.


  1. Python Developer’s Guide.↩︎

  2. ended on 1 January 2020.↩︎