Python from zero · with examples
Python for beginners — your first program in five minutes
Nothing to download. This page walks you through the first six things you need in Python: printing, variables, input, a condition, a loop and your own function. Each one comes with the code and what it prints.
1. Printing text
print shows whatever you put in the brackets. Text goes in quotes.
print("Hello, Python!")
Hello, Python!
2. Variables
A variable is a named box for a value. Put text in one, a number in another, then use them together.
name = "Maya"
points = 120
print(name, "has", points, "points")
Maya has 120 points
3. Input from the user
input() asks a question and returns text. To do maths with it, convert it with int().
number = int(input("Enter a number: "))
print("Double is", number * 2)
Enter a number: 21
Double is 42
4. Conditions
A condition decides which part of the program runs. The indentation (four spaces) says what belongs inside.
temperature = 28
if temperature > 25:
print("Too hot, let's go swimming.")
else:
print("Perfect coding weather.")
Too hot, let's go swimming.
5. Loops
A for loop repeats code as many times as you need, so you never write the same line five times.
for i in range(1, 6):
print(i, "x 7 =", i * 7)
1 x 7 = 7
2 x 7 = 14
3 x 7 = 21
4 x 7 = 28
5 x 7 = 35
6. Your own function
A function is a named piece of code you can reuse. This is where real programming starts.
def greet(who):
return "Hi " + who + "!"
print(greet("Leo"))
print(greet("Zoe"))
Hi Leo!
Hi Zoe!
What comes next
These six steps are the basics and cover roughly your first two weeks. Lists, dictionaries, files and your own projects come after that.
In the course every lesson has a task that is checked automatically, and when your program crashes, the tutor explains what went wrong.
Frequently asked questions
Do I need a powerful computer?
No. Python in PYTHONIA runs in the browser, so a school laptop or a phone is enough.
How old do you have to be?
Around eleven and up. If you can read and type, you can start.
What if my program does not work?
Read the error message — it names the line and the reason. In the course the tutor explains it for you.
Is the course available in Czech?
Yes, the whole course exists in English and Czech and you can switch any time.
Read next
Write your first program today
Creating an account takes a minute. Your first lesson takes five.
Start for free