What is a programming language?

Programs are to computer science what recipes are to cooking. i.e. a set of instructions. Python is one example of a programming language. There are thousands of programming languages developed by computer scientists such as C++, Java, JavaScript, GO, Ruby, BASIC, C#, Perl etc. There are differences and similarities between these languages.

Consider the languages mentioned above. All these languages are known as high-level computer languages.  High-level computer languages are more human-readable and easier to write than low-level languages. In a high-level language like python adding two numbers can be expressed as follows:
c= a+b
Simple and natural. Humans can understand this and use this.

But can a computer understand this?

A computer hardware can understand only low-level language known as machine language. So if you want to add two numbers, the computer understands it in binary notation (as 0s and 1s).

So how does a computer execute a high-level computer language like python in machine language?

There are two ways to do this: a high-level language can either be compiled or interpreted. C++, Java, C#, GO: These are compiled languages.

A compiler takes a program written in a high-level language and translate it into a similar program in machine language of some computer. It is a complex computer program. We call the input or the high-level program as source code. The computer executes the output or the resulting machine code.

An interpreter is also a program. It analyzes and executes the source code instruction by instruction as needed. It is a computer simulator that understands a high-level language.

The difference between interpreting and compiling is that compiling is a one-shot translation. After you compile the code, you do not need the source code. You can run the program repeatedly without any changes. But if you want to run an interpreted code, interpreter, and the source code both are needed every time you run the program. Hence compiled programs tend to be faster and interpreted programs tend to be flexible and interactive.

How do you run the same python code in different machines?

The CPU designers create their own machine language. The modern processors use binary instructions (as sequences of 0s and 1s) as the core language and how the instructions are encoded and how they are executed are different from each processor.

  • X86: Used by Intel and AMD processors in most desktops and laptops. eg: Intel Core i7
  • ARM: Used in mobile processors. Eg: Apple M1
  • MIPS: Used in some embedded systems and high-performance computing. eg: Sony PlayStation 2

A program written in a high-level language can be run in various kinds of computers if there is a suitable compiler or interpreter.

So If there is a python interpreter installed I can run the same Python program on my laptop and my mobile. Therefore high-level computer languages are portable.

Some of these details are extracted from the excellent book Python Programming: An Introduction to Computer science by Dr. John M. Zelle. There are thousands of tutorials and books to learn python today. I think this book is a great place to start learning about python programming for a beginner.