COURSE · 1 chapter · 20 lessons
Python
Learn how programming thinks, with fewer symbols in the way
Pick either this or the JavaScript course — you only need one. Chapter 1, "The basics of syntax", is ready, and the rest is being added in order.
Read about this chapter
Show text and numbers
- 02Numbers and mathsLet Python do the sums. A number is written without quotes, unlike text.Go to the exercises
- 03Dividing, and what is left overThere are three symbols for dividing. We will see why a tidy answer still comes out as a decimal.Go to the exercises
- 04The order things happen inTimes first, brackets even sooner. Here is how to make Python work things out the way you meant.Go to the exercises
- 05Joining text together
+is not only for numbers. It works on text too — but mix in a number and Python tells you off.Go to the exercises - 06Writing commentsEverything after
#is ignored. Leave a note for the you of next week.Go to the exercises
Give a value a name
- 07Making a variableGive a value a name, and you can call it back up as many times as you like.Go to the exercises
- 08Why bother with variablesIt all runs without them, so why use them? Put the two side by side and see.Go to the exercises
- 09Changing what is insideWhat is in a variable can be swapped out later. We will see why
x = x + 1makes sense.Go to the exercises - 10The shorter way to write it
x = x + 1can be writtenx += 1. It comes up so often that it is worth knowing.Go to the exercises - 11Dropping values into a sentenceWrite
{}insidef"..."and the contents of a variable land there. It is the way you will write most often.Go to the exercises - 12Changing what kind of value it isThe text
"10"and the number10are different things. Here are the tools for going between them.Go to the exercises
The rules of indentation
- 13The rules of indentingIn Python the spaces at the start of a line mean something. Get this now and you will not trip later.Go to the exercises
Branch on a condition
- 14Branching on a conditionWrite an
ifand your program has an opinion for the first time.Go to the exercises - 15Comparing bigger and smallerA comparison answers
TrueorFalse. Let us open up a condition and look inside.Go to the exercises - 16Asking whether things are the same
=puts in,==asks. This is the one beginners muddle most.Go to the exercises - 17The other roadWrite an
elseand you have somewhere to go when the condition does not hold.Go to the exercises - 18Splitting it more waysLine up some
elifs and you can have three roads, or four, or as many as you need.Go to the exercises - 19Combining conditionsIn Python it is
and, not&&. Being able to read it out loud is very Python.Go to the exercises - 20When there is nothing there
Noneis the value for "nothing at all". We will also hand values straight to a condition.Go to the exercises