Skip to content

Informatics Practices · Ch 3 — Brief Overview of Python

Introduction to Python

3.1

Introduction to Python

A computer, by itself, does nothing. It acts only when it is given instructions — and those instructions must be arranged in a definite order, because the machine executes them one after another. An ordered set of instructions or commands given to a computer for execution is called a program.

Instructions cannot be given to a computer in ordinary conversational English. They have to be written in a language designed for the purpose — a programming language. A programming language is the language we use to specify a set of instructions to the computer. Python, C, C++ and Java are all examples of programming languages; each has its own vocabulary and rules, but all serve the same role of letting a human describe, precisely, what the machine must do.

This chapter is a brief overview of one such language: Python.

Why Python?

Python was created by Guido van Rossum in 1991. Since then it has become one of the most widely used languages in the world, and two qualities account for that:

  • It is easy to learn — its statements read close to plain English, which makes it a natural first language.
  • It is versatile — the same language is used across a remarkable range of fields, including software development, web development, scientific computing, big data and Artificial Intelligence.

So the effort spent learning Python is not effort spent on a classroom-only tool; the identical language powers real applications in industry and research.

Which version to use

The programs in this chapter are written using Python 3.7.0. That exact version is not compulsory — installing any version of Python 3 is enough to type in and run every program that follows. What matters is staying within the Python 3 family, since that is the line of the language the programs are written for. Python can be downloaded and installed on your own computer to work along with the chapter.

What this chapter covers

The overview moves from the raw material of the language to complete working programs, in this order:

  • Introduction to Python
  • Python keywords
  • Identifiers
  • Variables
  • Data types
  • Operators
  • Expressions
  • Input and output
  • Debugging
  • Functions
  • if..else statements
  • for loop
  • Nested loops

Read the sequence as a build-up: first the words the language reserves for itself (keywords) and the names you are allowed to coin (identifiers), then the containers for data (variables) and the kinds of data they hold (data types), then the machinery for combining data (operators and expressions), the ways a program talks to its user (input and output), the craft of finding and fixing errors (debugging), and finally the structures that give a program shape — functions, decision-making with if..else, and repetition with loops.