Skip to main content

Foundations of Python Programming: Functions First

Section 1.3 The Python Programming Language

The programming language you will be learning is Python. Python is an example of a high-level language that is designed to be easily read by humans and where the human does not need to have specific knowledge about the computer hardware. Other high-level languages you might have heard of are C++, PHP, and Java.
As you can infer from the name high-level language, there are also low-level languages, sometimes referred to as machine languages or assembly languages. Loosely speaking, low-level languages use numerical codes or symbols to tell the computer how to process and move data. Generally, computers can only execute programs written in low-level languages. Thus, programs written in a high-level language have to be processed before they can run. This extra processing takes some time, which is a small disadvantage of high-level languages. However, the advantages to high-level languages are enormous.
First, it is much easier to program in a high-level language. Programs are shorter so they take less time to write, and being easier to read, they are easier to correct. Second, high-level languages are portable, meaning that they can run on different kinds of computers with few or no modifications. Low-level programs are based on the hardward for a particular kind of computer system and have to be rewritten to run on another.
Due to these advantages, almost all programs are written in high-level languages. Low-level languages are used for a few specialized applications where, being designed for a specific kind of computer, they can run very fast.
Two kinds of programs process high-level languages into low-level languages: interpreters and compilers. An interpreter reads a high-level program and executes it, meaning that it does what the program says one line at a time. It alternates between reading lines and performing computations.
A compiler reads the program and translates it completely before the program starts running. In this case, the high-level program is called the source code, and the translated program is called the object code or the executable. Once a program is compiled, you can execute it repeatedly without further translation.
Like many modern languages, Python uses both processes. Programs are first compiled into a lower level language, called byte code, and then interpreted by a program called a virtual machine. Because of the way programmers interact with it (often adding individual lines of code and then running their programms), and because of the speed of modern computers, Python is usually considered an interpreted language.
For the core material in this book, you will not need to install or run Python natively on your computer. Instead, you’ll be writing simple programs and executing them right in your browser.
However, if you are using this book for a course, you will need a complete Python environment, rather than the limited environment available in this online textbook. To do that, either install Python and an integrated development environment on your computer so that it can run natively, or use a remote server that provides a command line shell or IDE.

Note 1.3.1. Example IDEs (2023).

Downloadable: Visual Studio Code, PyCharm, Jupyter, Thonny
Online servers: Python Tutor
 1 
pythontutor.com
, Google Colaboratory
 2 
Colab
Check your understanding

Checkpoint 1.3.2.

    Source code is another name for:
  • the instructions in a program, written in a high-level language.
  • If the instructions are strored in a file, it is called the source code file.
  • the language that you are programming in (e.g., Python).
  • This language is simply called the programming language, or simply the language. Programs are writte in this language.
  • the environment/tool in which you are programming.
  • The environment may be called the IDE, or integrated development environment, though not always.
  • the number (or “code”) that you must input at the top of each program to tell the computer how to execute your program.
  • There is no such number that you must type in at the start of your program.

Checkpoint 1.3.3.

    What is the difference between a high-level programming language and a low-level programming language?
  • It is high-level if you are standing and low-level if you are sitting.
  • In this case high and low have nothing to do with altitude.
  • It is high-level if you are programming for a computer and low-level if you are programming for a phone or mobile device.
  • High and low have nothing to do with the type of device you are programming for. Instead, look at what it takes to run the program written in the language.
  • It is high-level if the program must be processed before it can run, and low-level if the computer can execute it without additional processing.
  • Python is a high level language but must be interpreted into machine code (binary) before it can be executed.
  • It is high-level if it easy to program in and is very short; it is low-level if it is really hard to program in and the programs are really long.
  • While it is true that it is generally easier to program in a high-level language and programs written in a high-level language are usually shorter, this is not always the case.

Checkpoint 1.3.4.

    Pick the best replacements for \(1\) and \(2\) in the following sentence:
    When comparing compilers and interpreters, a compiler is like \(1\) while an interpreter is like \(2\text{.}\)
  • 1 = pseudocode, 2 = an algorithm
  • Both compiling and interpreting are processes that convert a program into code that can be understood by a computer. Who is the audience for pseudocode and algorithms? Humans.
  • 1 = translating an entire book, 2 = translating a line at a time
  • Compilers take the entire source code and produce object code or the executable and interpreters execute the code line by line.
  • 1 = software, 2 = hardware
  • Both compilers and interpreters are software.
  • 1 = object code, 2 = byte code
  • Compilers can produce object code or byte code depending on the language. An interpreter produces neither.
You have attempted of activities on this page.