01 / 02

What are the common built-in data types in Python?

Difficulty: 2/10
sequence types, mapping types, numeric types

Although, Python doesn't require data types to be defined explicitly during variable declarations type errors are likely to occur if the knowledge of data types and their compatibility with each other are neglected. Python provides type() and isinstance() functions to check the type of these variables.

  1. 1

    None keyword represents the null values in Python. Boolean equality operation can be performed using these NoneType objects.

  2. 2

    There are three distinct numeric types - integers, floating-point numbers, and complex numbers. Additionally, booleans are a sub-type of integers.

  3. 3

    Sequence Types: According to Python Docs, there are three basic Sequence Types - lists, tuples, and range objects. Sequence types have the in and not in operators defined for their traversing their elements. These operators share the same priority as the comparison operations.

  4. 4

    Text strings such as str

  5. 5

    Binary data such as bytearray bytes memoryview

Scenario Questions

0-2 years experience

  1. 1You need to store a collection of unique user IDs that you will frequently check for membership. Which built‑in type would you choose and why?
  2. 2If you have a fixed sequence of configuration values that must never change, which type would you use and how would you create it?
  3. 3What does the expression `type(5)` evaluate to in Python, and what does that tell you about the object?

2-5 years experience

  1. 1You wrote a function that concatenates two lists and returns the result, but callers sometimes see the original lists modified. What could be causing that and how would you fix it?
  2. 2During a code review you notice a dict being used to store ordered items, but the code runs on Python 3.5 where dict order isn’t guaranteed. What alternative built‑in type would you suggest?
  3. 3Your team switched from a list of tuples to a list of dicts for readability, but performance dropped. Explain why and what trade‑offs are involved.

5-8 years experience

  1. 1We need to process a massive stream of numeric data and keep only the top 100 values. Which built‑in types and structures would you combine to achieve this efficiently?
  2. 2A legacy service serializes data using `repr()` of Python objects, and you need to ensure that complex nested structures deserialize correctly across versions. How do built‑in type choices affect this and what would you change?
  3. 3When designing an in‑memory cache for frequently accessed user sessions, how would you decide between using a dict of objects versus a list of namedtuples, considering mutability and memory overhead?

8+ years experience

  1. 1Our organization is migrating a large codebase from Python 2 to Python 3. Many modules rely on the behavior of `unicode` vs `str` and on dict ordering. What architectural guidelines would you set for handling built‑in type changes to avoid subtle bugs?
  2. 2We are building a cross‑language data pipeline where Python components exchange data with services written in Go and Java. How would you standardize the representation of Python built‑in types to ensure compatibility and long‑term maintainability?
  3. 3A team wants to replace a custom object‑serialization layer with JSON, but some of our data structures include sets and frozensets. How would you design a strategy for representing these built‑in types across services while preserving semantics?

Follow-up Questions

  • How does mutability affect passing these types to functions?
  • What are the performance trade‑offs between using a list and a tuple?
  • When would you prefer a set over a list for membership checks?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.