Introduction
Python Programming — 3 minute read
Python is an interpreted programming language. It can be used to solve almost any problem.
Remember that a programming language is just a tool. If you have a problem, you must choose a suitable language to solve that problem. At National 5 level, you only need to know the basics of HTML, CSS, SQL and Python.
This document should be a basic introduction to Python and its basic workings. To start with, we will first cover how programming works at a low level and why we need these languages.
Compiled vs Interpreted Languages
Computers are very stupid. They don’t actually understand what they are doing, they are a piece of rock which has been “tricked into thinking”. They work in a binary system meaning they only “understand” 1s and 0s (at the physical level, a low and a high voltage).
To get the computer to do something, we need to create a program. There are endless ways to do this depending on what you want the computer to do.
At first, there were no programming languages. Computer engineers had to manually enter 0s and 1s into a computer to get it to do something, this is known as Machine Code. This is the lowest level of programming you can write. The actual processing unit (CPU) inside the computer can understand these instructions.
Unfortunately, machine code is very difficult to read and understand, so a better solution was created known as Assembly Language. Assembly Language is machine code but uses more human terms to write the program but this still takes a long time. This is where “high level” programming languages come in.
High level languages make programs much easier to read and faster to code. This is a concept known as “abstraction”, it means that programmers can focus more on actually solving problems rather than having to deal with the small details of low level languages.
In order for the computer to “understand” high level languages, we can use something called a compiler. It is a translator for high level code to low level code. If you compile a program, you will get a single executable (.exe) file which you can run.
Compilers are not the only way to run a program. Scripting languages, such as Python and JavaScript, are not compiled. They are “interpreted”. Instead of compiling into an executable file, an interpreter will run the code line by line and compile “on the fly”. Regardless of choice, the program will always result in machine code the computer can understand.
Programming languages are all very similar but generally have their own unique way of solving problems. This similarity is the result of the C Programming Language.
C is one of the first widely used high level programming languages. The widespread use of the C resulted in the design of most languages being similar to C. Therefore, what you learn in one language is usually transferrable to other programming languages. All programming languages have what is known as Syntax.
Syntax
When we refer to “syntax”, we are effectively talking about the “grammar” of the programming language.
Just as grammar is a set of rules in which spoken language should be structured, syntax is a set of rules in which programming languages should be written.
Just as real-life languages have different grammar so do programming languages. They each have unique approaches on how they are written. Python is designed to be very readable and forgiving, almost like writing English.
A large part of Syntax are something known as Data Types. They are the first thing we will cover.