Getting Started with Python

Welcome to Lesson 1.
Today we begin with Python.
No dragons.
No complicated theory.
No mysterious computer rituals involving candles and ancient keyboards.
Just you, Python, a terminal, and your first program.
Very civilized.
Mostly.
Python is a programming language.
That means you can use it to give instructions to a computer.
The computer will follow those instructions exactly.
Not emotionally.
Not creatively.
Exactly.
This is both wonderful and dangerous.
If you tell Python to print a message, it prints a message.
If you forget one important symbol, Python complains.
If you write completely wrong code, Python does not say:
I understand what you meant emotionally.
It says:
SyntaxError
Very honest.
A little rude.
But useful.
What You Will Learn
In this lesson, you will learn:
- what Python is;
- how to install Python;
- how to check the Python version;
- how to open the Python interpreter;
- how to create your first Python file;
- how to run Python code from the terminal;
- how
print()works; - how comments work;
- why file names matter;
- what common beginner errors look like;
- how to practice safely.
By the end of this lesson, you will have your first working Python program.
Small program.
Big moment.
Very Python.
What Is Python?
Python is a programming language known for being readable and beginner-friendly.
A simple Python program can look like this:
print("Hello, World!")
This tells Python:
Show this text on the screen.
Very simple.
Very classic.
Very “welcome to programming, please fasten your seatbelt”.
Python is used for many things:
- automation;
- web development;
- scripts;
- backend applications;
- data analysis;
- testing;
- DevOps tools;
- artificial intelligence;
- file processing;
- small tools that save a lot of time.
Python is popular because it lets you write useful programs without too much syntax noise.
Some languages make you write a small novel just to print one sentence.
Python says:
print("Hello")
Much kinder.
Python is not perfect.
No language is perfect.
But Python is a very good place to start.
The Terminal
In this course, we will use the terminal.
The terminal lets you write commands to your computer.
Do not panic.
The terminal is not a monster.
It only looks like one when it is dark and blinking.
You will use it to:
- check Python version;
- run Python files;
- create folders;
- move between folders;
- test small commands.
The terminal is one of the best tools a developer can learn.
It looks simple.
But it gives you a lot of power.
Like a tiny control room.
With fewer buttons.
And more responsibility.
Install Python on Arch Linux
If you use Arch Linux, install Python with:
sudo pacman -S python python-pip
Then check the version:
python --version
You should see something like:
Python 3.x.x
The exact version may be different.
That is fine.
You need Python 3.
Python 2 is old.
Very old.
Like “please let it rest” old.
In this course, we use Python 3.
Install Python on Fedora
On Fedora, install Python with:
sudo dnf install python3 python3-pip
Check the version:
python3 --version
You should see:
Python 3.x.x
On some systems, the command is python3.
On others, it may also be python.
If python does not work, try:
python3
Computers enjoy making simple things slightly different.
Keeps life spicy.
Install Python on Ubuntu
On Ubuntu, install Python with:
sudo apt update
sudo apt install python3 python3-pip
Check the version:
python3 --version
You should see:
Python 3.x.x
Again, Ubuntu often uses:
python3
instead of:
python
So if you see examples using python, but your system wants python3, use python3.
Same language.
Different command name.
Very Linux.
Check Python Version
Run:
python --version
or:
python3 --version
You should get something like:
Python 3.12.3
The important part is:
Python 3
If you see Python 3, you are ready.
If the command is not found, Python is not installed correctly or the command name is different.
Try:
which python
or:
which python3
This shows where Python is installed.
Example:
/usr/bin/python
or:
/usr/bin/python3
Good.
Python exists.
The snake is awake.
Politely.
Open the Python Interpreter
You can open Python directly from the terminal.
Run:
python
or:
python3
You should see something like:
Python 3.x.x
Type "help", "copyright", "credits" or "license" for more information.
>>>
The >>> means Python is waiting for your code.
Try this:
print("Hello from Python!")
Press Enter.
You should see:
Hello from Python!
Congratulations.
You just gave Python an instruction.
Python obeyed.
This is how it begins.
Today:
print("Hello")
Tomorrow:
I accidentally automated half my work.
Beautiful.
Exit the Python Interpreter
To leave the Python interpreter, type:
exit()
Then press Enter.
Or press:
Ctrl + D
Now you are back in the normal terminal.
Important difference:
Inside Python, you write Python code:
print("Hello")
Inside the terminal, you write terminal commands:
ls
cd
python hello.py
Do not mix them.
If you type terminal commands inside Python, Python will be confused.
If you type Python code directly in the terminal, the terminal will be confused.
Everyone gets confused.
Nobody wins.
Create a Project Folder
Now let us create a folder for this lesson.
In the terminal, run:
mkdir python-course
cd python-course
mkdir lesson1
cd lesson1
Now check where you are:
pwd
You should see a path ending with:
python-course/lesson1
Good.
This is where we will create our first Python file.
Keeping files organized is important.
A messy project folder becomes a jungle.
And not the fun adventure kind.
The “where did I put main_final_final2.py” kind.
Create Your First Python File
Create a file called:
hello.py
You can use any code editor.
For example:
code hello.py
If you use another editor, open the file however you prefer.
Now write this code:
print("Hello, World!")
Save the file.
This is your first Python program.
Very small.
Very famous.
Very traditional.
Every programmer meets Hello, World! at some point.
It is like the handshake of programming.
A little boring.
But official.
Run Your Python File
In the terminal, make sure you are inside the same folder as hello.py.
Check files:
ls
You should see:
hello.py
Now run:
python hello.py
or:
python3 hello.py
You should see:
Hello, World!
Great.
You created a file.
You wrote Python code.
You ran it.
Python read your file and executed the instruction.
This is programming.
Not all of it.
But the door is open.
What Does print() Do?
The function print() shows text on the screen.
Example:
print("Hello, Python!")
Output:
Hello, Python!
You can print more than one line:
print("Hello!")
print("Welcome to Python.")
print("This is my first program.")
Output:
Hello!
Welcome to Python.
This is my first program.
Python runs the file from top to bottom.
First line.
Second line.
Third line.
Like reading instructions.
Very literal instructions.
If the code says print three lines, Python prints three lines.
If the code says something impossible, Python complains.
A very honest little machine.
Strings
Text inside quotes is called a string.
Example:
"Hello"
This is a string.
You can use double quotes:
print("Hello")
Or single quotes:
print('Hello')
Both work.
But be consistent.
Do not start with one quote and end with another.
Wrong:
print("Hello')
Python will not like this.
It will complain.
And honestly, it has a point.
You opened the door with one key and tried to close it with another.
Numbers
You can also print numbers:
print(10)
print(25)
print(100)
Output:
10
25
100
Numbers do not need quotes.
This is a number:
10
This is text:
"10"
They look similar to humans.
But Python sees them differently.
Python is very precise.
Sometimes painfully precise.
Like a strict accountant with a keyboard.
Simple Math
Python can do math.
Try:
print(2 + 3)
print(10 - 4)
print(5 * 6)
print(20 / 4)
Output:
5
6
30
5.0
Operators:
+ addition
- subtraction
* multiplication
/ division
Notice:
20 / 4
prints:
5.0
That is a decimal number.
Python division returns a decimal result.
Even if the result looks like a whole number.
Python has reasons.
Python always has reasons.
Sometimes it even tells you.
Comments
A comment is text inside your code that Python ignores.
Comments are for humans.
Use #.
Example:
# This line explains what the code does
print("Hello, Python!")
Python ignores:
# This line explains what the code does
and runs:
print("Hello, Python!")
Comments help you remember what your code does.
This is useful because future you will forget.
Future you is busy.
Future you has other problems.
Be kind to future you.
Write comments when they help.
But do not write comments like this:
# print hello
print("Hello")
That is obvious.
A better comment explains why something exists.
Example:
# Show a welcome message when the program starts
print("Welcome to my Python program!")
Much better.
File Names Matter
Use simple file names.
Good:
hello.py
calculator.py
my_script.py
lesson1.py
Bad:
my first python file.py
final version really final.py
test!!!.py
python.py
Avoid spaces in file names.
Use lowercase letters and underscores.
Also, do not call your file:
python.py
Why?
Because Python may confuse your file with Python itself or with modules.
That creates strange problems.
And strange problems waste life.
Use clear names.
Clear names are not boring.
Clear names are mercy.
Common Beginner Error: Command Not Found
If you run:
python hello.py
and see:
command not found: python
try:
python3 hello.py
Some systems use python3 instead of python.
If neither works, Python may not be installed.
Go back to the installation step.
Do not panic.
This is a setup problem.
Not a personal failure.
Computers are just dramatic sometimes.
Common Beginner Error: File Not Found
If you see something like:
python: can't open file 'hello.py': No such file or directory
it means Python cannot find your file.
Possible reasons:
- you are in the wrong folder;
- the file name is different;
- the file was not saved;
- you typed the name incorrectly.
Check your folder:
ls
If you do not see hello.py, you are not in the right place or the file does not exist.
Check where you are:
pwd
Move to the correct folder with cd.
The terminal is powerful.
But it does not guess where your file emotionally should be.
It needs the actual location.
Common Beginner Error: SyntaxError
Try this wrong code:
print("Hello"
Run it.
Python will show an error like:
SyntaxError: '(' was never closed
This means Python expected something more.
You opened ( but did not close it.
Correct:
print("Hello")
Errors are not enemies.
Errors are messages.
Annoying messages.
But messages.
Read them.
They often tell you what went wrong.
Sometimes clearly.
Sometimes like a mysterious old wizard.
But still.
Common Beginner Error: Missing Quotes
Wrong:
print(Hello)
Python thinks Hello is something like a variable name.
But we did not create a variable called Hello.
So Python complains.
Correct:
print("Hello")
Text needs quotes.
Remember:
Text wears quotes.
Numbers do not.
Very elegant.
Almost poetry.
Very nerdy poetry.
Your First Personal Program
Now change hello.py.
Write:
print("Hello!")
print("My name is Viktor.")
print("I am learning Python.")
print("Today I created my first Python program.")
Run:
python hello.py
or:
python3 hello.py
Output:
Hello!
My name is Viktor.
I am learning Python.
Today I created my first Python program.
You can change the name if you want.
The important thing is that you edit the file, save it, and run it again.
This cycle is very important:
write code
save file
run code
read output
fix errors
run again
This is how programming works.
Not glamorous.
Very real.
Very effective.
The Python Workflow
A simple beginner workflow:
1. Open your project folder.
2. Create or edit a .py file.
3. Save the file.
4. Run it from the terminal.
5. Read the output.
6. Fix mistakes.
7. Repeat.
This is the loop.
You will use this loop many times.
Thousands of times.
Maybe millions.
Programming is not writing perfect code immediately.
Programming is improving code step by step.
Like building something with small bricks.
Except some bricks shout SyntaxError.
Indentation Preview
Python cares about indentation.
Indentation means spaces at the beginning of a line.
Example:
if True:
print("This line is indented.")
Do not worry about if yet.
We will learn it later.
For now, just notice:
print("This line is indented.")
has spaces before it.
In Python, indentation is part of the code structure.
This is different from many other languages.
Python uses indentation to understand blocks of code.
So yes.
Spaces matter.
Python is very serious about furniture placement.
We will practice this properly in future lessons.
Practice
Create a file:
practice.py
Write:
print("Python is installed.")
print("I can run Python files.")
print("This is lesson 1.")
Run it:
python practice.py
or:
python3 practice.py
Now change the file:
print("Python is installed.")
print("I can edit files.")
print("I can run them again.")
print("Small steps become real skills.")
Run it again.
The goal is simple:
Edit.
Save.
Run.
Understand.
Do this until it feels normal.
This is not “too easy”.
This is the foundation.
Skipping foundations is how buildings become surprises.
Mini Challenge
Create a file called:
about_me.py
Write a program that prints five lines:
- your name;
- your country or city;
- why you want to learn Python;
- one thing you want to build;
- one funny sentence.
Example:
print("My name is Viktor.")
print("I live in Italy.")
print("I want to learn Python because it is useful.")
print("I want to build small tools and web applications.")
print("My computer and I are negotiating peacefully.")
Run it:
python about_me.py
or:
python3 about_me.py
If it works, good.
If it breaks, even better.
Read the error.
Fix the problem.
Run again.
This is how you become stronger.
Slowly.
Painfully.
Beautifully.
Very Python.
Summary
Today you learned:
- Python is a programming language;
- Python is readable and beginner-friendly;
- Python 3 is the version we use;
- the terminal lets you run Python commands;
python --versionorpython3 --versionchecks the version;- the Python interpreter lets you test code quickly;
.pyfiles store Python programs;print()shows output on the screen;- strings are text inside quotes;
- numbers do not need quotes;
- Python can do simple math;
- comments start with
#; - file names should be simple and clear;
- errors are normal;
- Python code is usually written, saved, and run many times.
This is a strong beginning.
You have installed Python.
You have run Python.
You have created your first file.
You have seen your first output.
Maybe you have seen your first error.
Good.
Errors are part of the road.
Not proof that you are bad.
Proof that you are coding.
Next Lesson
In the next lesson, we will learn about variables and data types.
You will learn how to store information in names like:
name = "Anna"
age = 25
price = 19.99
Variables are one of the most important ideas in programming.
They let your program remember values.
And once your program can remember values, it becomes much more useful.
Browsers forget.
Databases remember.
Python variables remember just enough to begin the adventure.
Very good.
Very Python.