Chapter 1: Introduction
Version: Python 3.13
What is programming, really?
Let's start with a story. Suppose you tell your younger brother: "Buy an egg from the shop." He goes, buys it, brings it back. Easy. Now suppose you want a robot to do the same job. The robot doesn't understand your language, and "buy an egg from the shop" as a single sentence means nothing to it. You have to tell it step by step: 1. Open the door 2. Step outside 3. Walk 50 steps to the right 4. Enter the shop 5. Say "One egg, please" 6. Pay the money 7. Come back home Writing instructions step by step — that is programming. And the language you write those instructions in is a programming language. Python is a language where the instructions read almost like plain English.
print("Go to the shop")
print("Buy an egg")
print("Come back home") A program is a list of steps, spelled out so exactly that a machine can follow them. Those 3 lines are a complete program! print means "show this text on the screen."
Why Python?
There are hundreds of programming languages. So why Python? 1. It reads like English. In another language, showing "Hello" on screen takes this much code (in Java):
public class Main public static void main(String[] args)
System.out.println("Hello");
In Python, just this:
print("Hello")
Which one do you like more? This is exactly why Python is the best start for beginners. 2. It rules the job market. AI, data science, websites, automation — whichever way you look, Python is there. Freelance work in Python is plentiful too. Few other languages open this many doors with a single skill. 3. The big players use it. Google, Netflix, Instagram — they all use Python. What you are learning is not a toy. It is a real industry tool.
Installing Python
Step 1: Go to python.org → Downloads → download the latest version for your system. Step 2: During installation, a checkbox appears — "Add Python to PATH". You must tick it! (Skip it and you will have trouble later.) Step 3: Verify. Open Terminal/CMD and type:
python --version
If it shows Python 3.13.x or something close — congratulations! The install worked.
GOTCHA
If typing python gives "not recognized", in 99% of cases the PATH checkbox was never ticked. Install Python again, and tick it this time.
Editor: Download VS Code for writing code (it's free). Install the Python extension — VS Code will suggest it on its own.
Your first program
Open VS Code, create a new file, name it hello.py . Then type exactly this:
print("I am a programmer!")
In the terminal, type:
python hello.py
The screen will show: I am a programmer!
You are now a programmer. Truly — every programmer on Earth started exactly here.
Let's understand each part
| Part | Meaning |
|---|---|
print | Python's built-in instruction — “show what is inside the brackets on the screen” |
( | Brackets — they tell print: “here is your stuff” |
) | |
"I am a programmer!" | Text inside double quotes = a string (text data) |
If you write text without quotes, Python thinks it is the name of an instruction — so text always goes inside "" or ' ' .
One instruction, three parts — the command, the brackets, and the text.
Try it yourself
1. Print your own name — the output should show your name. Answer
print("My name is Alex")
2. Write two print lines — "I" on the first line, "am learning" on the second. Answer
print("I")
print("am learning")
3. (Think a little) What is wrong with this code?
print(Hello)
Answer No quotes! `Hello` needs `""` around it — otherwise Python looks for an instruction named `Hello` and fails with `NameError: name 'Hello' is not defined`. Correct: `print("Hello")` You wrote a program — but if the name changes every time, will you edit the code again and again? No. In the next chapter we learn variables — the magic box that remembers names. See you there!
Chapter 2: Variables and Data Types
Version: Python 3.13
The magic box
In the last chapter you wrote print("My name is Alex") . Now imagine you have to print your name in 50 places. Will you type it 50 times? And if the name changes, will you fix it in 50 places? The answer is the variable — a named magic box that holds data inside it.
name = "Alex"
print(name)
print(name)
print(name) Here name is the name of the box, and "Alex" is what's inside. Put something in the box once, then use it as many times as you like. To change the name, change it in just one place:
name = "Alex"
print(name)
# Alex
name = "Maria"
# the thing inside the box changed
print(name)
# Maria Three boxes, three types — the value inside decides the type. See? The = sign does not mean "equal" like in math — it means "put the thing on the right into the box on the left". Programmers call this assignment.
What can go in the box? — Data types
A box holds more than text. It can hold many kinds of things. Each kind is called a data type:
age = 24
# int — whole number (integer)
price = 99.99
# float — decimal number
name = "Alex"
# str — text (string)
is_student = True
# bool — true/false (boolean)
| Type | Meaning | Examples |
|---|---|---|
int | whole number | 24, -5, 0 |
float | decimal number | 3.14, -0.5 |
str | text | “Alex”, 'hi' |
bool | true/false | True, False |
Want to know what's inside a box? Ask type() :
age = 24
name = "Alex"
print(type(age))
# <class 'int'>
print(type(name))
# <class 'str'> NOTE
The T in True and the F in False are capital — Python will not recognize true . This is the most common beginner mistake.
Rules for naming
You can't name a box just anything — there are 3 rules:
my_name = "Alex"
# OK — lowercase, underscore
myName = "Alex"
# works, but not the Python convention
2name = "Alex"
# WRONG — cannot start with a number
my-name = "Alex"
# WRONG — a hyphen means minus! The rules: a name must start with a letter or _ ; inside, letters, numbers and _ are fine; spaces and hyphens are not. And don't use Python's own words ( print , if , for ) as names. A good name is half the understanding: age = 24 is a thousand times better than x = 24 .
A fun truth
In many other languages, when you create a box you must declare "this box will hold only numbers". Python needs none of that — the box figures out what's inside by itself. The same box can hold a number first and text later:
x = 10
print(type(x))
# int
x = "Now I am text"
print(type(x))
# str — the box changed, no problem at all! The same box, a new kind of value — Python does not lock a variable to one type.
Try it yourself
1. Create three variables: your name ( str ), your age ( int ), whether you are a student ( bool ) — then print all three. Answer
name = "Alex"
age = 24
is_student = True
print(name)
print(age)
print(is_student) 2. What will this code output? (Think before you run it!)
a = 5
b = a
a = 10
print(b) Answer `5`. When you do `b = a`, the value `a` has at that moment (5) is copied into `b`. Later, when `a` changes, `b` does not — they are two separate boxes. 3. Find the mistake: my-age = 24
print(my-age) Answer You can't use a hyphen (`-`) in a name — Python thinks you are subtracting `age` from `my`. Correct: `my_age = 24` You know the box now — next we do math with what's inside it: addition, subtraction, division — and there is a fun trap in division that we'll look at too!
Chapter 3: Numbers and Math
Version: Python 3.13
Python as a calculator
Open Python, type numbers, and it becomes a calculator. In the VS Code terminal, type python and press Enter — a >>> sign appears. This is interactive mode: type, press Enter, get the answer at once.
>>> 2 + 3
5
>>> 10 - 4
6
>>> 3 * 7
21 To get out, type exit() .
Operators — the math signs
| Sign | Meaning | Example | Result |
|---|---|---|---|
+ | add | 5 + 3 | 8 |
- | subtract | 5 - 3 | 2 |
* | multiply | 5 * 3 | 15 |
/ | divide | 7 / 2 | 3.5 |
// | whole division | 7 // 2 | 3 |
% | remainder | 7 % 2 | 1 |
** | power | 2 ** 3 | 8 |
Notice two things: 1. / always gives a decimal — even 4 / 2 gives 2.0 , not 2 ! Use // when you want whole-number division. 2. % (remainder) is surprisingly useful. Is a number even or odd?
print(10 % 2)
# 0 → even
print(7 % 2)
# 1 → odd The division trap
A fun question: if 10 chocolates are shared equally among 3 people, how many does each person get?
print(10 / 3)
# 3.3333333333333335
print(10 // 3)
# 3 (3 each)
print(10 % 3)
# 1 (1 left over) Plain /, whole-number //, and remainder % — three different questions, three different answers. Three operators together tell the whole story!
Which comes first? — Precedence
2 + 3 * 4 = how much? 20 or 14? The math rule applies here too — multiplication before addition: the
answer is 14 .
print(2 + 3 * 4)
# 14
print((2 + 3) * 4)
# 20 — brackets always come first
print(2 ** 3 ** 2)
# 512 — powers run right to left: 2^(3^2) Python does brackets and powers first, multiplication next, addition last — the BODMAS rule from school, built in. An easy way to remember: brackets → powers → multiply/divide → add/subtract. When in doubt, add brackets — being clear beats being wrong.
Changing type — conversion
"5" (text) and 5 (number) are not the same thing:
print("5" + "3")
# 53 (two pieces of text joined)
print(5 + 3)
# 8 (two numbers added) To turn text into a number:
num = int("42")
# "42" → 42
price = float("9.99")
text = str(100)
# "9.99" → 9.99
# 100 → "100" int(), float() and str() change a value's type — but only when the value makes sense as that type.
GOTCHA
int("abc") will crash! int() only works on text that looks like a number. Remember this when converting text a
user typed — in Chapter 12 we learn how to handle it safely.
Shortcuts — change yourself
count = 10
count = count + 5
# old value + 5
print(count)
# 15 This pattern is so common that it has a shortcut:
count = 10
count += 5
# same thing: count = count + 5
count -= 3
# count = count - 3
count *= 2
# count = count * 2 Handy functions
print(round(3.14159, 2))
# 3.14 — 2 places after the decimal
print(abs(-7))
# 7 — absolute value
print(min(4, 9, 2))
# 2
print(max(4, 9, 2))
# 9
print(pow(2, 10))
# 1024 — same as 2**10 Try it yourself
1. A rectangle has length 12 and width 5 — find its area. Answer
length = 12
width = 5
area = length * width
print(area)
# 60 2. If 100 dollars are shared equally among 7 people, how much does each person get, and how much is left? Answer
print(100 // 7)
# 14 (each person)
print(100 % 7)
# 2 (left over) 3. What is the output?
x = 5
x += 3
x *= 2
print(x) Answer `16`. Step by step: x = 5 → `x += 3` makes x = 8 → `x *= 2` makes x = 16. Numbers are done — now we play with text (strings): pulling the first letter out of a name, reversing text, and the magic of f-strings!
That was the start. The book keeps going for 23 more chapters.
The full book: 172 pages, 26 chapters and 10 step-by-step projects — strings, conditionals, loops, functions, files, classes, Flask, pandas and Tkinter windows — for $3.99. Or take all 11 programming books in the bundle for $12.99.