Open workspace
Python 1.2Code walkthrough7 min5 parts

Run Your First Python Code

Run Python in a notebook and know what happens when a cell executes.

In this lesson5 parts

  1. 01Your first Python code: print, strings and the execution count
  2. 02Python statements: one per line, round brackets, backslashes and semicolons
  3. 03Comments with the hash sign, and why triple quoted strings are not comments
  4. 04The kernel, NameError, tracebacks, and Restart and run all
  5. 05Recap and your challenge

Key terms

The words this lesson introduces, each in one line. The module’s glossary collects them all.

function · argument
a named piece of code that does one job · a value passed to it
string
text, written in quotes
statement
one instruction
comment
text after #, skipped when the code runs
kernel · execution count
runs the cells and keeps their names · the order cells ran

Quiz 5 questions

Answer each one in your head, or on paper, before you check it. Getting one wrong here is how the lesson sticks.

  1. 01

    What does print(Hello) (no quotes) give?

  2. 02

    A cell contains only 2.25 + 1.25 + 3.50, with no print. What does the notebook show?

  3. 03

    After a restart, you run only total = bread + milk + eggs. What happens?

  4. 04

    What does the interpreter do with # total of the three items?

  5. 05

    Which way of splitting a long statement over two lines is recommended?

Practice

Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.

The self-checking notebook for this lesson is Notebook 1 · Getting Started.

Common mistakes

What you will see when it goes wrong, why it happens, and the fix.

Where it’s used

Where this lesson’s ideas turn up in real work.