The basics of syntax

INPUT · Slides

Numbers and maths

01 / 06

A number goes in as it is

You wrapped text in ". A number you do not wrap. You write 100, just like that.

That is not a rule for the sake of it. Leaving the quotes off is how you say to Python "this one is a value you can do sums with".

print(100)

Result

100

02 / 06

"100" and 100 are not the same

They look alike, but to Python "100" and 100 are two different things.

  • "100" … three symbols, a 1 and two 0s, sitting side by side — text
  • 100 … the number one hundred

On screen they come out looking the same. Only one of them can be added up.

print("100")print(100)

Result

100
100

03 / 06

Adding and taking away

+ adds, - takes away. Put the sum inside the brackets of print and the answer comes out.

The working itself is invisible. You only find out the answer by showing it, so sums and print go together.

print(3 + 4)print(10 - 4)

Result

7
6

04 / 06

Times is * (an asterisk)

You do not use × for multiplying. You use *** (an asterisk)**. The reason is simple: there is no × on a keyboard.

Spaces around the symbols make no difference. 3*4 and 3 * 4 mean exactly the same, but the spaced-out one is easier to read, so that is how this course writes it.

print(6 * 7)

Result

42

05 / 06

Wrap it in quotes and nothing gets worked out

Here is the important bit. Wrap it up as "3 + 4" and it becomes text, not a sum.

Python does not read what is inside the quotes as something meaningful. It is just symbols in a row.

print(3 + 4)print("3 + 4")

Result

7
3 + 4

06 / 06

A long sum can go in one go

You can chain up as many + and - as you like. They are worked out from the left.

Instead of tapping a calculator one key at a time, you write the whole sum and take back the answer.

print(1 + 2 + 3 + 4 + 5)

Result

15