Write a script that prints the type of one value from each of Python's core built-in categories.
Python's built-in types fall into a few families. There are numbers, sequences, mappings and sets, plus the two special types None and bool. The quickest way to show them is to build one value from each family and then ask the interpreter what that value is.
values = {
'int': 10,
'float': 3.5,
'complex': 2 + 3j,
'str': 'python',
'bytes': b'ab',
'bool': True,
'list': [1, 2, 3],
'tuple': (1, 2),
'set': {1, 2},
'dict': {'a': 1},
'range': range(3),
}
for name in values:
value = values[name]
print(name, '->', type(value).__name__, '->', repr(value))
The output pairs each value with its type name. You get int, float, complex, str, bytes, bool, list, tuple, set, dict and range.
Two observations are worth making out loud. First, the built-in sequence types, which are str, bytes, list and tuple, share the same set of abilities. They all support len(), they all let you index into them, they all let you take a slice, and they can all be used in a for loop. That shared interface is the reason so much Python code can be written once and used with many different kinds of data. Second, there is no separate type for a single character and no separate type for an array of whole numbers. A character is simply a string with one character in it, and there is no built-in numeric array type, because that is what the array module is for.
Also notice that range is a type in its own right and not a function that returns a list. It produces its numbers as they are needed, so it uses very little memory. That is the reason that a for loop over a large range does not allocate anything up front.