Skip to the solution
EasyBackend13 min read

What are Python's built-in data types?

418 views

The problem

Question presented to candidate: "Python is dynamically typed, but every value still has a type. Walk me through the built-in data types you use day to day, how you would group them, and which of them can change after they are created."

What a strong answer should cover:

  • The groups: numbers (int, float, complex, bool), text and binary (str, bytes, bytearray), sequences (list, tuple, range), the mapping dict, sets (set, frozenset) and None (type NoneType).
  • Which are mutable (list, dict, set, bytearray) and which are immutable, and why that decides what can be a dict key (hashability).
  • Precise behaviour: int has arbitrary precision, float is a 64-bit IEEE 754 double (so 0.1 + 0.2 is not 0.3), bool is a subclass of int, / always returns a float.
  • Dynamic but strong typing: names have no type, objects do, and 1 + "1" raises TypeError instead of converting.
  • A CPython or version detail: dict keeps insertion order as a language guarantee since 3.7, type() vs isinstance(), or the 4300-digit int/str conversion limit.

Code / implementation expected: Optional β€” a few type() / isinstance() calls or a short table of literals is enough.

  • data-types
  • basics

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

13 min read Β· 10 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

PythonEvery built-in type, bool as int, big ints, floats and strong typing
PythonContainer families, hashability and the 1 / 1.0 / True dict key

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 25 of 139 in Python

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Python questions
Up nextEasy

How do you sort with a custom key, and how does sorted differ from sort?

Continue