Open workspace
Python 1.4Code walkthrough7 min4 parts

Data Types

Know the basic types and how they convert.

In this lesson4 parts

  1. 01Python data types: type, int, float, complex, bool, str and None
  2. 02Dynamic typing and type annotations, and why Python does not check them
  3. 03Type conversion: int truncation, ValueError, TypeError on plus, and why bool of the string False is True
  4. 04Recap and your challenge

Key terms

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

int · float · complex · bool · str · None
whole number · decimal number · complex number · True/False · text · no value
type annotation
the intended type, age: int = 7; not checked by Python

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 is bool("False")?

  2. 02

    What is int(-7.9)?

  3. 03

    What does int("10p") give?

  4. 04

    items: int = "three" — does Python raise an error?

  5. 05

    What is the type of None?

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 2 · Variables and Data Types.

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.