What is programming?
🌍 In real life. Think of making tea at a tea stall: boil the water, add the tea leaves, add milk and sugar, pour it into a cup. If you swap two steps, say you pour the cup before the water boils, the tea goes wrong. A good recipe is a list of exact steps, in the right order.
A computer is like a helper who is incredibly fast but has no common sense. It never guesses what you meant. It does exactly what the steps say, in exactly the order they are written.
The idea in one sentence: a program is a list of exact instructions, and the computer follows them one by one, from top to bottom.
Its words:
- code: the instructions, written in a programming language
- program: a whole set of code that does a job
- run: tell the computer to follow the program now
- output: what the program shows you on the screen
Step by step, what happens when you press Run:
- Python looks at the first line of your code.
- It does what that line says.
- It moves to the next line, and the next, until there are no lines left.
Watch the robot. It can't skip a step or change the order, and neither can a computer:
Like this robot, a computer follows each step in order.
How Python does it. Deep inside, a computer only understands long patterns of 0s and 1s, which are very hard for people to write. So we write in a programming language: words and symbols that people can read. Python is a program that reads your code line by line and turns each line into actions the computer can do.
Why Python? It's one of the most popular programming languages in the world. It's used for websites, data science, AI, games and automation, and it's famous for reading almost like English.
Here is your very first Python program. It tells the computer to show a message on the screen. Click Try it, then press Run in the editor on the right.
print("Hello, Python!")A program can have many instructions. Python runs them one by one, from top to bottom.
print("Good morning!")
print("I am learning Python.")
print("This is fun!")Mistakes and edge cases.
- Capital letters matter.
Print("Hi")givesNameError: name 'Print' is not defined. Python only knowsprint, in small letters. - Text needs quotes.
print(Hello)givesNameError: name 'Hello' is not defined: without quotes, Python thinks Hello is a name it should look up. - Every bracket you open, you close.
print("Hi"givesSyntaxError: '(' was never closed. - Curly quotes from a word processor don't work. Code copied from a document may have “ ” instead of " ". Python stops with
SyntaxError: invalid character '“' (U+201C). Type the quotes yourself in the editor.
💡 Don't worry about breaking anything. Code you write here can't harm your computer. Experiment freely: change the message and run it again!
Quiz
What is a program?
- A list of instructions for a computer
- A type of computer screen
- A computer that thinks by itself
In what order does Python run your instructions?
- Top to bottom, one by one
- Bottom to top
- All at the same time
What does this program print?
print("Hi!") print("Bye!")What is Python used for?
- Only for games
- Websites, data science, AI and much more
- Only for calculators
Which line stops this program with an error?
print("Hi!") Print("Bye!")
Coding tasks
Write a program that shows exactly this message:
Hello, Python!Show these two lines, in this order:
I am learning Python It is fun