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 mappingdict, sets (set,frozenset) andNone(typeNoneType). - Which are mutable (
list,dict,set,bytearray) and which are immutable, and why that decides what can be a dict key (hashability). - Precise behaviour:
inthas arbitrary precision,floatis a 64-bit IEEE 754 double (so0.1 + 0.2is not0.3),boolis a subclass ofint,/always returns a float. - Dynamic but strong typing: names have no type, objects do, and
1 + "1"raisesTypeErrorinstead of converting. - A CPython or version detail:
dictkeeps insertion order as a language guarantee since 3.7,type()vsisinstance(), 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.