Python for complete beginners · Unit 1: Getting started · Lesson 1 of 24
Lesson 1: What is programming? Your first Python program
Start here if you have never written code before. You'll find out what programming really is, meet Python, and write and run your very first program – right here in your browser.
0 of 24 lessons finished
By the end of this lesson you will be able to
- say in your own words what a program is
- explain what Python is and why we use it
- run your first program in the editor
- use print() to show a message on the screen
- know that the computer follows your lines in order, from the top
A program is a list of instructions
A program is a list of instructions that tells a computer what to do. That's it. Every app on a phone, every game, every website is made of instructions that a person wrote down.
You already know about instructions. A recipe is one: "Crack two eggs into a bowl. Whisk them. Pour them into a hot pan." You do the steps in order, from the top, one at a time. A computer program works the same way.
Programming (also called coding) is the job of writing those instructions. The instructions themselves are called code.
Computers are fast, but very literal
Here is the big difference between you and a computer. If a recipe says "add the eggs" and forgets to say "crack them first", you would still crack them. A computer would not. It does exactly what it is told – no more, no less – and it never guesses what you meant.
Try this with a friend: ask them to act as a robot and make a jam sandwich, following only your words. "Put the jam on the bread" might end with a whole jar balanced on a loaf! Programmers learn to give instructions that are clear, complete and in the right order. That is the real skill, and you will practise it in every lesson.
Programs are everywhere
- A phone alarm: when the time is 7:00, play a sound.
- Traffic lights: show green, wait, show amber, wait, show red.
- A game: if the player touches a coin, add 1 to the score.
- A washing machine: fill with water, spin, drain, spin faster.
Someone wrote each of those programs. By the end of this course, you will be able to write programs like them.
What is Python?
Deep down, a computer only understands long patterns of 0s and 1s. Nobody wants to write those! So people invented programming languages: ways of writing instructions that humans can read, which the computer can then turn into its own 0s and 1s.
Python is one of the most popular programming languages in the world. It was created by Guido van Rossum and first released in 1991. (It's named after the comedy show Monty Python's Flying Circus, not the snake.) People choose Python because:
- It reads almost like English.
print("Hello")prints the word Hello. - It's used for real work – in science, websites, games, data and artificial intelligence.
- It's great for beginners, so it's taught in many schools.
On this site, Python runs right inside your web browser. There is nothing to download or install, and your code stays on your own device.
How Python runs your code
When you press Run, a program called the interpreter reads your code. It starts at line 1, does what that line says, then moves to line 2, then line 3, and so on down to the end. Anything your program shows on the screen is called the output.
Doing the lines in order, from the top, is called sequence. It is the first of the big ideas in programming, and it's why the order of your lines matters.
Your first program
Since the 1970s, programmers learning a new language have started with the same tiny program: one that says Hello, World! It's also the motto of our Computing department. Press Run and watch the output box.
Try it Press Run. Then change the code and run it again.
print("Hello, World!")
Output
Congratulations – you are now a programmer! Let's look at what you wrote:
printis an instruction built into Python. It means "show this on the screen". We call it a function; you'll learn more about functions later in the course.- The round brackets
( )hold the thing you want to print. - The quote marks
" "show where the text starts and ends. Text in quote marks is called a string.
The quote marks are not printed. They are just there to tell Python "this is text, not an instruction".
Meet the editor
The box you just used is the editor. Every lesson has several of them. Here is what each part does:
- The code area (with line numbers down the left). Click in it and type. Line numbers help when Python tells you about a problem on "line 2".
- Run runs your code. On a keyboard, Ctrl + Enter does the same.
- Output is where anything your program prints appears.
- Start again puts the original code back, so you can never break anything for good.
The first time you press Run, the page takes a moment to load Python. After that it's quick.
Try it Now change it. Replace World with your own name, keep the quote marks, and press Run again.
print("Hello, World!")
Output
One line after another
A program can have as many lines as you like. Python runs them in order, from the top.
print("Ready")
print("Steady")
print("Go!")
It prints:
Ready Steady Go!
| Line | What it does |
|---|---|
| 1 | Python starts here and prints Ready. |
| 2 | Then it moves down and prints Steady on a new line. |
| 3 | Last of all it prints Go!. There are no more lines, so the program ends. |
Each print starts a new line of output. Now swap the order: move print("Go!") to the top and run it. The output changes, because the order of the lines is the order of the instructions.
Try it Press Run. Then change the code and run it again.
print("Ready")
print("Steady")
print("Go!")
Output
Your turn
These exercises are checked by Classfern as soon as you press Check. If you get stuck, press Stuck? for a nudge, then a hint, and only then the answer. Getting things wrong is part of learning – nobody sees your attempts but you.
Exercise 1 of 4 Change the message Fix or change the code✓ Done
Change this program so that it prints exactly: Hello, Classfern!
The exercise opens here when you scroll to it. It needs JavaScript switched on.
Stuck? Get a nudge
Mr Babbage: You only need to change one word, and it's inside the quote marks.
Still stuck? Get a hint
Mr Babbage: Keep print( and both quote marks. Replace World with Classfern – capital C.
Show me the answer
Try typing it yourself rather than copying – it sticks better.
print("Hello, Classfern!")
Exercise 2 of 4 Predict the output Predict the output✓ Done
Without running it, what will this program print? Type the output exactly, one line per print.
The exercise opens here when you scroll to it. It needs JavaScript switched on.
Stuck? Get a nudge
Mr Babbage: Python runs the lines from the top. Each print makes one line of output.
Still stuck? Get a hint
Mr Babbage: The first two lines print the same word. Don't type print or the quote marks – only what appears on the screen.
Show me the answer
Try typing it yourself rather than copying – it sticks better.
The output is:
Hip Hip Hooray!
Exercise 3 of 4 Put the countdown in order Put the lines in order✓ Done
Build a program that counts down 3, 2, 1 and then prints Blast off! One line is a trap and isn't needed.
The exercise opens here when you scroll to it. It needs JavaScript switched on.
Stuck? Get a nudge
Mr Babbage: The order of the lines is the order things happen.
Still stuck? Get a hint
Mr Babbage: Start with print("3"). Leave out the line with a capital P.
Show me the answer
Try typing it yourself rather than copying – it sticks better.
print("3")
print("2")
print("1")
print("Blast off!")
(Leave out Print("1") – the capital P would cause an error.)
Exercise 4 of 4 Write it yourself Write the code✓ Done
Write a program from scratch that prints these two lines exactly:
My first program
works!
The exercise opens here when you scroll to it. It needs JavaScript switched on.
Stuck? Get a nudge
Mr Babbage: One print makes one line of output. How many lines do you need?
Still stuck? Get a hint
Mr Babbage: Line 1 of your program prints My first program. Line 2 prints works! Each needs print, brackets and quote marks.
Show me the answer
Try typing it yourself rather than copying – it sticks better.
print("My first program")
print("works!")
Common mistakes
| Wrong | Right | Why |
|---|---|---|
Print("Hello") | print("Hello") | Python cares about capital letters. print must be all lower case. |
print("Hello) | print("Hello") | Every opening quote mark needs a closing one, so Python knows where the text ends. |
print("Hello" | print("Hello") | Every opening bracket needs a closing bracket. |
print(Hello) | print("Hello") | Without quote marks, Python thinks Hello is the name of something, not text. |
print(“Hello”) | print("Hello") | Curly “smart quotes” from a word processor won't work. Type straight quotes in the editor. |
Quick quiz
Five quick questions to check you've got the main ideas. They're marked as you go.
5 questions. Pick an answer for each one – if it's wrong, have another go. Finish them all to complete the lesson.
The quiz opens here when you scroll to it. It needs JavaScript switched on.
Recap
- A program is a list of instructions. Programming is writing them.
- Computers do exactly what they're told, in order, from the top (sequence).
- Python is a popular language that reads almost like English.
print("…")shows text on the screen. Text in quote marks is a string.- Capital letters, brackets and quote marks all matter.
Next lesson, you'll find out much more about print and strings: printing several things at once, numbers and sums, and quote marks inside text.
Key words from this lesson
Tap or hover over a word for its meaning, or open the full glossary of code.
Finished?
Complete the quiz (60% or more) and this lesson is ticked off on your progress bar automatically – or tick it yourself.
About this lesson
How it's marked: exercises and quizzes are marked by Classfern in the browser – a practice check, not an exam. Your code and progress stay in this browser; we never see them.
Coach tips: Mr Babbage and Miss Lovelace pop up with tips on your first visit. Untick Coach tips at the top of the lesson (or press "All tips off" on a tip) to switch them off. Show me how always works.
Curriculum: England national curriculum, computing KS3: use a textual programming language; design, write and debug programs.
Python is a registered trademark of the Python Software Foundation. Classfern is independent and is not affiliated with or endorsed by it.
Python course home · Glossary of code · Programming Department