← All lessons
Python intermediate · Lesson 1 of 11

Before you start

This course follows Python basics. If you've done that, skim this page; if you've learned Python elsewhere, it's a quick check that we mean the same things by the same words.

  • A variable is a name for a value, made with = (read it as "becomes"). Values have a type: int (whole number), float (decimal), str (string, text in quotes), bool (True or False).
  • if, elif and else choose which block runs. A block is the indented lines under a line ending in a colon.
  • while repeats while a condition is True; for x in things: runs once per item. range(a, b) counts from a up to b - 1. break leaves a loop and continue skips to the next item.
  • A list is [1, 2, 3]. Items are numbered by index from 0, items[-1] is the last, and items[1:3] is a slice. A method is a function called with a dot, like items.append(4).
  • A function is defined with def, takes parameters, and sends a value back with return. A function without return gives back None.
def total_over(prices, limit):
    total = 0
    for p in prices:
        if p > limit:
            total += p
    return total

print(total_over([4, 12, 7, 20], 5))
Prints
39

If every line of that makes sense, you're ready. If not, the matching Python basics lesson is the place to go back to.

Practice

What does this print?

x = 7
x = x * 2 - 1
print(x)
More info