Python Types

int, float, str, bool, None — and how to check them correctly

35 min · interactive lesson with runnable code and 9 graded exercises.

What you'll be able to do

  • Know what each built-in type represents and its common operations
  • Explain / vs //, float precision, and string immutability
  • Tell falsy apart from missing (None)
  • Choose between type() and isinstance() — and say why

int

Whole numbers

int represents whole numbers — positive, negative, or zero.

The arithmetic operators look familiar, but two of them (/ and //) trip people up in interviews. Play with them below — the results follow Python's exact rules.

float

Decimal numbers

float represents decimal numbers. In ML, metrics, probabilities, learning rates, and most preprocessed features are floats.

Now the most famous interview gotcha. Run this:

Decimal values are stored in binary floating-point, and some decimals (like 0.1) can't be represented exactly. The lab shows the exact value really stored in memory.

str

Text

str represents text. Single or double quotes both work, and Python strings are Unicode by default.

Common operations — edit and re-run to explore:

Indexing and slicing are interview staples (palindromes, reversals, windows). Get a feel for them here:

bool

Truth values

bool has exactly two values: True and False. Comparisons produce bools, and and / or / not combine them.

Python also treats every value as truthy or falsy in an if. Falsy values: False, None, 0, 0.0, "", and empty containers ([], {}, set(), ()). Test your instincts:

None

The absence of a value

None represents “no value”. It's like null in JavaScript, but Python has a single None object (a singleton) of type NoneType.

  • default initial value
  • missing or not-yet-computed value
  • optional function arguments
  • what a function returns when it has no return

Here's why this matters in real code — a default argument where 0 is a perfectly valid age:

type() vs isinstance()

Checking types correctly

type(obj) returns the exact type. isinstance(obj, T) asks “is this a T — or a subclass of it?” Explore it with real Python:

The same idea with your own classes:

Need to accept several types? Pass a tuple:

Type facts worth remembering

Quick wins in interviews

Common pitfalls

Spot the bug