1. Introduction Python¶
1.1. 👋 Getting started¶
Welcome to our first lecture!
📘 What Is a Programming Language?¶
A programming language is a structured way to communicate instructions in a way computers can understand. It allows humans to write commands that computers can interpret and execute.
There are many programming languages. But like spoken languages, some programming languages are easier to learn than others — and Python is one of the most beginner-friendly.
📋 Key Characteristics¶
- Syntax:¶
The rules that define the structure and format of code. Example: if (x > 0) { ... }
is valid syntax in many languages.
- Semantics:¶
The meaning behind the syntax—what the code does when run.
- Abstractions:¶
Features like variables, functions, loops, and objects that help programmers build complex systems more easily.
🧩 Types of Programming Languages¶
🔹 High-Level Languages¶
Languages like Python, Java, and C++ are easier to to read, write, and understand. Python, in particular, is known for being almost like English.
🔹 Low-Level Languages¶
Languages like Assembly or C are closer to the machine's binary instructions and offer more control. or C. These give you much more control over the computer, but they’re much harder to write and understand.
🔹 Machine Languages¶
It is just pure binary. This is what the computer actually understands. No one can write it directly.
In terms of language, machine and human are opposites; the language that is easy for humans to understand is hard for machines to understand, and vice versa.
🧩 Programming Language Classification¶
🔹 Compiled Languages¶
These are translated into machine code before running. Examples: C
, Rust
, Go
🔹 Interpreted Languages¶
Executed line-by-line by an interpreter. Examples: Python
, JavaScript
, Ruby
💡 Why Are Programming Languages Important?¶
Programming languages are the foundation of all software. They allow us to:
- Build websites and mobile apps
- Build AI models
- Analyze data and run scientific models
- Create games and simulations
- Control robots and hardware, etc.
🗣️ In short: A programming language is how we tell computers what to do.
1.2. How Python Actually Works (Behind the Scenes)¶
📌 Step-by-Step: What happens when you run a Python script?¶
Step 1: You write code
You save a
hello.py
file with Python code, like:print("Hello, world!")
Step 2: The Python Interpreter is invoked
When you run a script using
python hello.py
, the Python interpreter starts up.Step 3: Compilation to Bytecode
The parse tree is converted into bytecode — a low-level, intermediate representation of your code. The bytecode is saved as
.pyc
files inside the__pycache__
directory.Step 4: Execution by the Python Virtual Machine (PVM)
This bytecode gets sent to a PVM (basically a mini-computer inside your computer). The PVM spits out the result in good old binary — 101001 — so your computer understands what to do.
⚙️ Python Compiler (Interpreter)¶
To run a Python script, we only do for Step 1. The Steps 2, 3, and 4 are done through a compiler. There are several Python compiler as follows:
Implementation | Language Used | Performance | Compilation Type | Platform Integration | Notes |
---|---|---|---|---|---|
CPython (default) | C | Moderate | Bytecode (interpreted) | Native (cross-platform) | Reference implementation; most widely used |
PyPy | RPython | High (with JIT) | JIT Compilation | Cross-platform | Much faster for long-running programs |
Jython | Java | Moderate | Compiled to Java bytecode | JVM-based | Integrates with Java libraries |
IronPython | C# | Moderate | Compiled to .NET IL | .NET/Mono | Works well with C# and .NET libraries |
MicroPython | C | Low | Interpreted (lightweight) | Embedded systems | Designed for microcontrollers |
Brython | JavaScript | Low | Transpiled to JS | Web browsers | Runs Python in the browser |