Skip to main content

2.1 Built-in Types in Python

Python’s standard types are documented in stdtypes. The major families are numeric, sequence, mapping, set, and special singleton/utility types.

Numeric types

  • int: arbitrary precision integers
  • float: double-precision floating-point values
  • complex: complex numbers with .real and .imag
  • bool: subclass of int with values True and False

Sequence types

  • list: mutable ordered collection
  • tuple: immutable ordered collection
  • range: immutable arithmetic progression object
  • str: immutable Unicode text sequence
  • bytes, bytearray, memoryview: binary sequence family

Mapping and set types

  • dict: mutable key/value mapping (keys must be hashable)
  • set: mutable collection of unique hashable elements
  • frozenset: immutable set

Truth value testing

Objects are truthy/falsy according to the standard truth-testing rules. Common falsy values include:

  • False
  • None
  • numeric zero values
  • empty containers ('', [], {}, set(), ())

Practical rules from official docs

  • Use list.sort() for in-place sorting and sorted() for new sorted output.
  • Prefer explicit type conversion (int(x), float(x), str(x)) when needed.
  • Avoid relying on bool being an int subtype for readability.

Official references