Quick answer
Python does not have a fixed set of primitive types. Every value is an object. The built-in types can be grouped in several ways, and one practical grouping uses seven categories: numeric, text, sequence, mapping, set, boolean and None. This is one common grouping, not an official count from the Python documentation.
The seven categories
- Numeric. Holds int, float and complex numbers. Examples:
age = 30,price = 9.99,z = 2 + 3j. - Text. Holds str, the string type. Example:
name = "Ada". - Sequence. Holds ordered collections: list, tuple and range. Examples:
scores = [90, 85],point = (3, 4),range(5). - Mapping. Holds dict, which stores key and value pairs. Example:
user = {"name": "Ada", "age": 30}. - Set. Holds unordered collections of unique items: set and frozenset. Example:
tags = {"python", "code"}. - Boolean. Holds bool, with the values True and False. A bool is a subtype of int, so
True + 1gives 2. - None. Holds NoneType, which has one value, None, that means no value. Example:
result = None.
Some guides count the binary types (bytes, bytearray and memoryview) as a separate category. This grouping leaves them out, and some guides fold text into the sequence group.
Mutable and immutable types
Mutability matters more day to day than the category name. An immutable object cannot be changed in place. A mutable object can.
| Immutable | Mutable |
|---|---|
| int, float, complex | list |
| str | dict |
| tuple, range | set |
| bool, frozenset |
Calling append() on a list changes that list. Calling a method on a string returns a new string and leaves the original as it was.
Checking a type
The type() function shows the type of a value. For example, type(3.5) returns <class 'float'>.
To check whether a value belongs to a type or a category, use isinstance(). Because bool is a subtype of int, isinstance(True, int) returns True.
How this compares with primitive types
Python’s built-in types behave like primitives in everyday code, but the language does not formally separate primitive types from other types. For a comparison with Java and JavaScript, see primitive vs non primitive data types.
Python’s list is the closest everyday equivalent to an array in other languages. If you are asking is an array a composite data type, the short answer is yes in most languages, and a list plays that role in Python.