Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
Every value in Python is an object, and every object has an identity, a type and a value. The type decides what you can do with the object and, in the Python language reference’s words, whether it can be changed: “An object’s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.” This guide lists the built-in object types, shows which are mutable and which can be used as dictionary keys, and walks through the checks and error messages you meet when a research script mixes them up.
What it is used for in research
Research code moves data between lists of identifiers, dictionaries of metadata, tuples of coordinates and strings read from files. Most silent bugs in these scripts come from three facts about types: some objects change in place and others do not, only hashable objects can be dictionary keys or set members, and two names can point at the same object. Knowing the type taxonomy lets you predict those behaviours instead of discovering them in a results table.
The standard library reference groups the built-in types by section: numeric types (int, float, complex), sequence types (list, tuple, range), the text sequence type (str), binary sequence types (bytes, bytearray, memoryview), set types (set, frozenset), mapping types (with dict as the standard example) and the Boolean type (bool). Arrays and data frames from NumPy and pandas are not on that list; they are covered below under free alternatives and in the NumPy array guide and the DataFrame creation guide.
Install or access
The built-in types need no installation: they are part of the Python interpreter. The interpreter and its documentation are published by the Python Software Foundation at python.org, and the main type reference is the “Built-in Types” page of the Python 3 library documentation at docs.python.org. NumPy, pandas and the other scientific libraries have their own official documentation at numpy.org and pandas.pydata.org.
Step-by-step: inspect any object
Three built-in functions answer most type questions. Each is described on the “Built-in Functions” page of the Python documentation.
- Find the type.
type(obj)with one argument returns the type of an object. - Test the type.
isinstance(obj, int)returns True if the object is an instance of the class, or of a direct, indirect or virtual subclass of it. The documentation recommends isinstance() over type() for testing the type of an object because it takes subclasses into account. It also accepts a tuple of types, for exampleisinstance(x, (int, float)). - Compare identity.
id(obj)returns an integer that is guaranteed to be unique and constant for that object during its lifetime. Theisoperator compares identities, soa is btells you whether two names point at the same object.
A short session, run on Python 3.14.6, shows all three. Your own output should match the lines below if you use a current Python 3 release.
>>> a = [1]; b = a; b.append(2)
>>> print(a, a is b, id(a) == id(b))
[1, 2] True True
>>> print(type(True), isinstance(True, int), type(True) is int)
<class 'bool'> True False
>>> print(type(range(3)), type({1}), type(b"a"), type(1j))
<class 'range'> <class 'set'> <class 'bytes'> <class 'complex'>
Assigning b = a did not copy the list. It gave the same object a second name, so appending through b changed what a shows. The Boolean lines show why isinstance() matters: the documentation states that bool is a subclass of int, so isinstance(True, int) is True even though type(True) is int is False. The same page says relying on that is discouraged and that you should convert explicitly with int().
Output and how to read it
The table below follows the Built-in Types and Data Model pages of the Python documentation. “Hashable” means the object can be a dictionary key or a set member.
| Type | Docs section | Mutable? | Usable as dict key or set member? |
|---|---|---|---|
| int, float, complex | Numeric Types | No (numbers are immutable) | Yes |
| bool | Boolean Type (a subclass of int) | No | Yes |
| str | Text Sequence Type | No; strings are immutable sequences of Unicode code points | Yes |
| list | Sequence Types | Yes; lists are mutable sequences | No |
| tuple | Sequence Types | No; tuples are immutable sequences | Yes, unless it contains an unhashable value, which raises TypeError |
| range | Sequence Types | No; an immutable sequence of numbers | Yes, as an immutable sequence |
| set | Set Types | Yes | No; a mutable set has no hash value |
| frozenset | Set Types | No | Yes; the frozenset type is immutable and hashable |
| dict | Mapping Types | Yes (dictionaries are mutable) | No; keys must be hashable, so values containing lists, dictionaries or other mutable types cannot be keys |
One subtlety changes how you read the Mutable column. The Data Model page says the value of an immutable container that holds a reference to a mutable object can change when that object changes, and adds that “immutability is not strictly the same as having an unchangeable value.” Real output shows it:
>>> t = ([1, 2], "x")
>>> t[0].append(3)
>>> print(t)
([1, 2, 3], 'x')
>>> t[1] = "y"
TypeError: 'tuple' object does not support item assignment
The tuple is still immutable, because it cannot rebind its slots, yet its contents changed. For dictionary work, see the dictionary guide, which covers dict itself.
Troubleshooting
TypeError: unhashable type: ‘list’
You used a list, set or dict where a hashable object is required. The Python documentation says dictionary keys must be hashable, so lists, dictionaries and other mutable types cannot be keys. Real output:
>>> hash([1])
TypeError: unhashable type: 'list'
>>> {[1, 2]: "a"}
TypeError: cannot use 'list' as a dict key (unhashable type: 'list')
Use a tuple of the same values instead ({(1, 2): "ok"} works), or a frozenset when order does not matter. If the tuple itself holds a list, hashing it raises the same TypeError, as the documentation warns for immutable sequences that contain unhashable values.
A sorted list prints None
The documentation states that methods which add, remove or rearrange the members of a mutable collection in place, and do not return a specific item, never return the collection itself but None. So x.sort() returns None and changes x:
>>> x = [3, 1, 2]
>>> print(x.sort())
None
>>> print(x)
[1, 2, 3]
Writing x = x.sort() therefore replaces your list with None. Call x.sort() on its own line, or use sorted(x) when you want a new list.
A change to one variable shows up in another
Two names for one mutable object, as in the identity example above. Check with a is b, and make an explicit copy when you need an independent object.
Building a long string in a loop
The documentation notes that there is no mutable string type, and that str.join() or io.StringIO can be used to build a string efficiently from many fragments.
Free alternatives
NumPy and pandas are free, open-source libraries that add their own types on top of the built-ins. Neither is a built-in type, and each documents its typing on its own site.
| Library | What it adds | What its documentation says |
|---|---|---|
| NumPy | The dtype object | A data type object describes how the bytes in the fixed-size block of memory for an array item should be interpreted, including type, size and byte order. An item extracted from an array is a Python object whose type is the scalar type for that dtype. |
| pandas | Series and DataFrame with a dtype per column | For many types the underlying array is a numpy.ndarray, and pandas may extend NumPy’s type system with custom arrays. When a DataFrame holds mixed types and strings are involved, the resulting array is of object dtype. |
For hands-on use see the NumPy array guide, the DataFrame creation guide and Python for exploratory data analysis.
FAQ
What are the built-in object types in Python?
The Built-in Types reference lists numeric types (int, float, complex), sequence types (list, tuple, range), str, binary sequence types (bytes, bytearray, memoryview), set types (set, frozenset), mapping types (with dict as the standard example) and bool.
Which Python types are mutable?
Lists, dictionaries and sets are mutable. Numbers, strings, tuples, ranges and frozensets are immutable.
Should I use type() or isinstance()?
The Python documentation recommends isinstance() for testing the type of an object, because it takes subclasses into account. For example, isinstance(True, int) is True because bool is a subclass of int.
Why can a tuple be a dictionary key but a list cannot?
A dictionary key must be hashable. Tuples are immutable sequences and can be keys when everything inside them is hashable; lists are mutable and are not hashable.
Are NumPy arrays and pandas DataFrames built-in Python types?
No. They come from the NumPy and pandas libraries, not from the interpreter’s built-in types.
Sources
Official documentation, checked 2026-10-29.
- Python Software Foundation, “Built-in Types”, The Python Standard Library: https://docs.python.org/3/library/stdtypes.html
- Python Software Foundation, “Data model”, The Python Language Reference: https://docs.python.org/3/reference/datamodel.html
- Python Software Foundation, “Built-in Functions”: https://docs.python.org/3/library/functions.html
- NumPy documentation, “Data type objects (dtype)”: https://numpy.org/doc/stable/reference/arrays.dtypes.html
- pandas documentation, “Essential basic functionality”: https://pandas.pydata.org/docs/user_guide/basics.html







