Prerequisites:
- Python
- IDE (Integrated Development Environment) or Text Editor (e.g. Visual Studio Code, PyCharm, Sublime Text, Atom, Notepad++)
What will you learn in this workshop?
- How does computer work?
- What is programming?
- What is Python?
- Basic Python syntax
- Variables
- Data types
- Why data types are important?
- Type casting
- Arithmetic and comparison operators
Hardware is the physical components of a computer. It includes:
- CPU (Central Processing Unit)
- RAM (Random Access Memory)
- Storage (HDD, SSD)
- Input/Output devices (Keyboard, Mouse, Monitor, Printer)
- Motherboard
- Power Supply
- Cooling system
- Case
- More about computer hardware
Software is a collection of instructions that tell the computer how to work. It includes:
- Operating System (Windows, macOS, Linux)
- Applications (Word, Excel, Chrome, etc.)
- Drivers
- More about computer software
The computer works by executing a series of instructions. It includes:
- The CPU fetches the instruction from the memory.
- The CPU decodes the instruction.
- The CPU executes the instruction.
- Repeat the process until the program is finished.
- The CPU sends the result to the output device.
- The CPU waits for the next instruction.
An instruction is a command that tells the computer what to do. It includes:
- Arithmetic operations (add, subtract, multiply, divide)
- Logical operations (AND, OR, NOT)
- Data transfer (move data from one place to another)
- Control flow (if, else, while, for)
- More about computer instruction
Decoding is the process of translating the instruction into a series of signals that the CPU can understand. It includes:
- Reading the instruction from the memory.
- Identifying the operation to be performed.
- Fetching the data from the memory.
- Performing the operation.
- Storing the result back to the memory.
- More about computer decoding
Memory is a storage device that stores data and instructions. It includes:
- RAM (Random Access Memory)
- ROM (Read-Only Memory)
- Cache
- More about computer memory
Programming is the process of creating a set of instructions that tell the computer how to perform a task. It includes:
- Writing code
- Testing code
- Debugging code
- More about programming
- To automate repetitive tasks
- To solve complex problems
- To create software applications
- To build websites
- To develop games
- etc.
Code is a set of instructions written in a programming language. It includes:
- Variables
- Data types
- Operators
- Control structures
- Functions
- Classes
- etc.
A programming language is a formal language that specifies a set of instructions that can be used to produce various kinds of output. It includes:
- Python
- C/C++
- C#
- Rust
- Java
- JavaScript
- etc.
Python is a high-level, interpreted, interactive, and object-oriented scripting language. It includes:
- Easy to learn
- Easy to read
- Easy to maintain
- Portable
- Extensible
Python syntax is the set of rules that defines how a Python program will be written and interpreted. Syntax is like the grammar of a programming language.
Following code will print "Hello, World!" to the console.
# This is a comment
print("Hello, World!")Console is a text-based interface that allows users to interact with the computer. It includes:
- Command Prompt (Windows)
- Terminal (macOS, Linux)
- Python Shell (IDLE)
- More about console
CLI (Command Line Interface) is a text-based interface that allows users to interact with the computer using commands.
GUI (Graphical User Interface) is a visual interface that allows users to interact with the computer using graphical elements.
Variables are used to store data in a computer program. RAM only holds values as 8-bit binary numbers (0s and 1s).
| address | value (binary) | real value |
|---|---|---|
| 100 | 00001010 | 10 |
| 101 | 00010100 | 20 |
| 102 | 00011110 | 30 |
# Assigning values to variables
a = 10 # address 100
b = 20 # address 101
c = 30 # address 102
# Printing variables
print(a)
print(b)
print(c)Output:
10
20
30
Variables should be declared with a data type in some programming languages. Python is a dynamically typed language, so you don't have to declare the data type of a variable. However behind the scenes, Python does assign a data type to the variable.
| Data type | Description | Example |
|---|---|---|
| int | Integer | 10 |
| float | Floating-point number | 10.5 |
| str | String | "Hello, World!" |
| bool | Boolean | True, False |
RAM
| address | value (binary) | real value | Variable |
|---|---|---|---|
| 100 | 00001010 | 10 | a |
| 101 | 00000001 | True | d |
floats and string are stored in a different way in memory. and require more than 8 bits to store. Floating-point number representation
Strings are stored as a sequence of characters in memory. characters are stored as ASCII values in memory. characters are stored as 8-bit binary numbers (0s and 1s).
| address | value (binary) | real value | Variable |
|---|---|---|---|
| 200 | 01001000 | H | c |
| 201 | 01100101 | e | |
| 202 | 01101100 | l | |
| 203 | 01101100 | l | |
| 204 | 01101111 | o | |
| 205 | 00101100 | , | |
| 206 | 00100000 | ||
| 207 | 01010111 | W | |
| 208 | 01101111 | o | |
| 209 | 01110010 | r | |
| 210 | 01101100 | l | |
| 211 | 01100100 | d | |
| 212 | 00100001 | ! |
# Assigning values to variables
a = 10 # int
b = 10.5 # float
c = "Hello, World!" # str
d = True # bool
# Printing variables
print(a)
print(b)
print(c)
print(d)Output:
10
10.5
Hello, World!
True
Data types are important because they tell the computer how to interpret the data stored in the memory. As we saw in memory, the computer stores data in binary format (0s and 1s).
If we try to add an integer and a string, the computer will not be able to perform the operation because it doesn't know how to interpret the data.
a = 10
b = "20"
print(a + b)Output:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Type casting is the process of converting one data type to another data type. It allows us to perform operations on different data types.
a = 10
b = "20"
print(a + int(b))Output:
30
Operators are used to perform operations on variables and values.
# Arithmetic operators
a = 10
b = 20
print('a + b =', a + b) # Addition
print('a - b =', a - b) # Subtraction
print('a * b =', a * b) # Multiplication
print('a / b =', a / b) # Division
print('a % b =', a % b) # Modulus
print('a ** b =', a ** b) # Exponentiation
print('a // b =', a // b) # Floor division
# Comparison operators
print('a == b:', a == b) # Equal
print('a != b:', a != b) # Not equal
print('a > b:', a > b) # Greater than
print('a < b:', a < b) # Less than
print('a >= b:', a >= b) # Greater than or equal to
print('a <= b:', a <= b) # Less than or equal toOutput:
a + b = 30
a - b = -10
a * b = 200
a / b = 0.5
a % b = 10
a ** b = 100000000000000000000
a // b = 0
a == b: False
a != b: True
a > b: False
a < b: True
a >= b: False
a <= b: True