Everything else is ready: study the parts, the key terms and the quiz below.
- Part 11Your first Python code: print, strings and the execution count
- Part 22Python statements: one per line, round brackets, backslashes and semicolons
- Part 33Comments with the hash sign, and why triple quoted strings are not comments
- Part 44The kernel, NameError, tracebacks, and Restart and run all
- Part 55Recap and your challenge
Run Your First Python Code
Run Python in a notebook and know what happens when a cell executes.
In this lesson5 parts
- 01Your first Python code: print, strings and the execution count
- 02Python statements: one per line, round brackets, backslashes and semicolons
- 03Comments with the hash sign, and why triple quoted strings are not comments
- 04The kernel, NameError, tracebacks, and Restart and run all
- 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.
- 01
What does
print(Hello)(no quotes) give? - 02
A cell contains only
2.25 + 1.25 + 3.50, with no print. What does the notebook show? - 03
After a restart, you run only
total = bread + milk + eggs. What happens? - 04
What does the interpreter do with
# total of the three items? - 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.