The basics of syntax

INPUT · Slides

Your first Python

01 / 07

What is Python?

Python is a programming language built around being easy to read.

It turns up in schoolwork, in scripts that do the boring parts of a job, in crunching numbers, in artificial intelligence — all over the place. It is also the language people hear about first when they decide they want to start programming.

There are few symbols to get past, and what you write reads almost like an English sentence. That makes it a good fit for a small phone keyboard, too.

02 / 07

A program runs from the top down

A program runs one line at a time, from the top, in the order you wrote it.

Code that looks hard is, in the end, just small instructions stacked up. Let us learn the first one.

03 / 07

Showing something with print

The first instruction to learn is print(). It puts whatever you write between the brackets on the screen.

The place it appears is called the console. On this screen it shows up on the right, or underneath if you are on a phone.

print("Hello!")

Result

Hello!

04 / 07

Wrap text in "

When you want to show some text, the rule is to wrap it in " (a double quote).

If you forget, Python thinks it is a name and you get a NameError.

print("Good morning")

Result

Good morning

05 / 07

No symbol at the end of a line

Python has no symbol that goes at the end of an instruction. The line break itself is the marker that says one instruction ends here.

Write one instruction per line. Write two lines and you get two lines of output, top to bottom.

print("Good morning")print("Good night")

Result

Good morning
Good night

06 / 07

Do not start a line with a space

This is where people trip up first. A space at the start of a line means something, so putting one there by accident is an error.

On a phone your finger slips and a space sneaks in easily. When you see an error, look at the start of the line first.

print("morning") print("noon")

Result

IndentationError: unexpected indent

07 / 07

Now have a go

From here you get your hands on it.

First 3 questions to trace the shape, then 10 to practise. Errors are fine — you just fix them. That is what programming is.