Your first line of Python

A program is a list of instructions, and Python reads them from the top down, one line at a time. The very first instruction most people learn is print(), which shows something on the screen.

print("Hello, world!")

Three things are going on in that one line:

  • print is the name of a function, a ready-made command that Python already knows.
  • The round brackets ( ) hold what you hand to the function.
  • "Hello, world!" is a string: a piece of text. The quotes tell Python "this is text, not code". Single quotes work too: 'Hello'.

Forget the quotes and Python tries to treat Hello as the name of something, gets confused, and throws an error. That is not you breaking the computer. Errors are just Python saying "I don't understand", and you will read lots of them.

Each print() puts its text on a new line. You can also give print() several things separated by commas, and it puts a space between them:

print("I am", 15, "years old")

Lines starting with # are comments. Python ignores them completely; they are notes for humans (including future you, who will have forgotten everything).

One more thing: type the code yourself. Copy-paste teaches your clipboard, not your brain. Hit Run, read the output, change something, run it again. That loop is the whole job.

Try it yourself

Edit it. Break it. Run it again.
# Python runs these lines from top to bottom
print("Hello, world!")
print("Python is reading this line second.")
print("You can print numbers too:", 42)
print('Single quotes work as well.')
Ctrl/Cmd + Enter runs. Esc, then Tab, leaves the editor.

Your turn

Type it yourself. That is the whole trick.

1Say hello

Make the program print exactly this one line:

Hello, Python!

Capital letters, comma and exclamation mark all count.

# Change the text inside the quotes
print("Hello")
Ctrl/Cmd + Enter runs. Esc, then Tab, leaves the editor.

2Three lines

Print three lines, in this order, using three print() calls: Ready, then Set, then Go!

print("Ready")
Ctrl/Cmd + Enter runs. Esc, then Tab, leaves the editor.

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.