Introduction
Contents
1. Introduction#
Before we start with programming, it is helpful to define a common background so that you can better understand the concepts of the following chapters. In order to know how to program efficiently, it is helpful to have some background knowledge about computers and computer architecture. Don’t worry though - we will only touch the surface here, without going too much into details.
1.1. Hardware vs. software#
Let us begin with the essential difference between software and hardware. By the term hardware, people refer to the physical components that make up a computer, e.g: CPU, main memory, hard drive, keyboard, mouse, etc. On the other hand, the term software refers to computer programs, that are a sequence of instructions that a computer, or the hardware that makes a computer, can execute and output a result to the user.

Fig. 1.1 Software vs Hardware#
1.2. What is programming?#
Programming is the process of writing code or software (computer programs). The people who write software are called programmers. As stated before, programs are sequences of instructions that can be interpreted by computers (more precisely, hardware components of a computer). From the figure above, we can see how software and hardware are related in the programming context - the programmer writes code (software) and runs it in a computer (hardware) to get some results.
1.3. Computer architecture#
How is the hardware of a computer able to process the software and generate results? To understand this, it is important to have a high-level view of the main components that make up a computer.

Fig. 1.2 Computer Architecture#
We will interpret Fig. 1.2 from left to right. We will start with the input devices. They allow us to interact with the computer and input data. Examples of such devices include: keyboard, USB sticks, mouse, CDs, etc. Then the middle part of the figure shows the most important components of a computer. This is where the magic happens. You can see the secondary storage. This is where data is saved permanently or until you decide to delete it. Examples include Hard Disk Drives (HDD) and Solid State Drives (SSD). Then main memory (also known as Random Access Memory) is another type of storage, which is volatile, meaning that once a process is completed or electricity is cut off, everything that resides there will be gone. Main memory communicates with the secondary storage to get data. These data data will be sent to the CPU (Central Processing Unit), which applies some instructions to these data to process them. Both data and instructions are loaded into memory. As far as main memory and secondary storage are concerned, there is no distincion between what is instructions and what is data: CPU is able to distinguish those since it applies instructions to the data that it gets from the memory. Also the figure shows the ALU (Arithmetic and Logic Unit) that is part of the CPU. This is like the brain of the CPU, responsible for most of the operations taking place there. The last part of the figure shows the output devices, which are devices used to render output. Examples include the monitor, printer, etc.
1.4. Data representation#
It is intuitive for us to have everything organized in files that we can open and read. However, the letters and numbers that we can distinguish and understand do not make sense to a computer. Computers can only understand sequences of 0s and 1s (binary code). For this reason, there is a whole pipeline of code that translates files and data from human readable form to a sequence of 0s and 1s. Each 0 or 1 is called a bit. Each bucket (cell) of the main memory can hold only a 0 or a 1. This sequence of 0s and 1s is then transferred to the CPU for processing. The CPU is able to parse this sequence of 0s and 1s. In addition, in the secondary storage everything is stored as a sequence of 0s and 1s as well. In Fig. 1.3 you can see how a file is broken down in lines, each line in words, each word in characters, each character in a bit sequence and each bit sequence in bits which are ultimately processed by the components of the computer.

Fig. 1.3 Data representation#
1.5. A bit of history#
As you may already know by now, Python is an object oriented programming language. It was launched in 1991 by Guido van Rossum. Nowadays, Python is one of the most popular programming languages due to its wide capabilities and the plethora of libraries that it offers.
1.6. IPython Interpreter, Python environments and libraries#
The IPython Interpreter is a terminal window (like cmd in Windows, terminal in macOS and bash in Linux). There you can run code directly.
A Python environment is like a sandbox. It provides a list of packages needed for a project to be run. In this way, if an environment file is included with the code everyone can recreate this environment by downloading the packages listed there. This guarantees that the code will run across multiple devices without problems caused by missing packages or different package versions.
Libraries in Python are reusable pieces of code which allow us to avoid reinventing the wheel. In other words, libraries contain code that is useful for our programs. It saves us a lot of coding and testing time. Libraries are one of the strongest advantages of Python when compared to some other programming languages. The Python Standard Library is one of the libraries that contains modules that we will use throughout this book.
Warning
Python is a space sensitive programming language, this means that adding extra space at the beginning of a line or adding extra indentation would result in a compilation error.