What is programming and Python?
tags: #python/intro
Overview of a Computer Architecture

The computer consists of 5 main components:
| Component | Description |
|---|---|
| Central Processing Unit (CPU) | Essentially the "brain" of the computer. The CPU is responsible for executing instruction and performing calculations (via the arithmetic logic unit (ALU). Tasks include: fetching instructions from memory, decoding them, executing them, and storing results. |
| Main (Primary) Memory or Random Access Memory (RAM) | Temporary storage. This is where data and instructions are stored for immediate access by the CPU (processor) for actively used data and instructions during the operation of a computer system. |
| Secondary Memory | Long-term memory. Permanent. Slower access times but can retain data even when the computer is turned off. |
| Input/Output Devices | Mediums in which you interact with the device. Input: keyboard, mouse; Output: monitor, printers. |
| Network | Essentially a slower and unreliable form of secondary memory retrieved over the network. |
What is programming?
In simple terms, programming is the act of writing or creating instructions for a computer to perform specific tasks. This is executed by the central processing unit (CPU) i.e., the main processors that executes a set of stored instructions in a computer program.
Note: When executing the program, the code is converted into machine-readable instructions that the CPU can understand and execute (e.g., from high-level programming language (e.g., Python) into binary code)
An algorithm refers to a set of well-defined and logical sequence of instructions to perform a specific tasks, whereas programming involves translating/implementing the set of well-defined and logical sequence of instructions into actual code (e.g., Python, Java, C++).
Python as a Programming Language
Majority of programs are written using high-level languages (e.g., Python, JavaScript) which are converted into machine language using translators.
High level languages are closer to human-language, providing a more intuitive and readable syntax.
Translators are required to convert programs written in higher-level languages into machine language for actual execution by the CPU.
Two Types of Translators
- Interpreters: which translates code line by line for execution (slower).
- Compilers: which translates the entire source code into machine-language for execution at once (faster).
Python is an interpreted language. The code we write is referred to as the source code, which is read by the interpreter.
Reserved Words
Python has a predefined set of reserved words in the program; i.e., they cannot be used as identifiers for other programming elements e.g., function names or variables.
and del global not with
as elif if or yield
assert else import pass
break except in raise
class finally is return
continue for lambda try
def from nonlocal while
Python Scripts vs Interactive Mode
Python offers two primary modes of execution: running Python scripts and interactive mode.
1. Python Scripts
Python scripts are files with a .py extension that contain Python code. This can be executed by running the Python interpreter and providing the script file as an argument to the command terminal:
python script.py
2. Interactive Mode
In interactive mode, you can type Python code directly into the interpreter, and it will be executed immediately. Each line of code is evaluated and the result is displayed immediately.
Python scripts are used to run larger programs or execute a sequence of Python code saved in a file, while interactive mode provides an immediate and interactive environment for executing code line by line.