On this page
type
Prev: tuple | Up: __builtins__ | Next: vars
Rel: bool, int, float, complex, str, Python Object, MRO & Initialization Dunder Flow
Ref: docs.python.org — type
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import type
Overview & Signature
type(object) -> the object's type
type(name, bases, dict, **kwds) -> a new type
Common Methods & Attributes
type.mro(self, /)— Return a type's method resolution order.
Usage
assert type(42) is int
# 3-argument form dynamically creates a new class: type(name, bases, namespace)
Point = type("Point", (), {"x": 0, "y": 0})
assert Point().x == 0
Gotchas
- Use
isinstance(x, cls)instead oftype(x) is clsunless you intentionally want to exclude subclasses (e.g., excludingboolwhen checkingint).
REPL Inspect
help(type)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/tuple
- tuts/python3/__builtins__/vars
- tuts/python3/python metaprogramming
- tuts/python3/tutorials/advanced_python_internals/python_object_mro_and_initialization
- tuts/python3/tutorials/core_fundamentals/syntax_and_variables
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/tuple Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/vars Linked here; links to this page; shared tags: #builtins
- tuts/python3/tutorials/advanced_python_internals/python_object_mro_and_initialization Linked here; links to this page
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/bool Linked here; shared tags: #builtins
- tuts/python3/__builtins__/complex Linked here; shared tags: #builtins
- tuts/python3/__builtins__/float Linked here; shared tags: #builtins
- tuts/python3/__builtins__/int Linked here; shared tags: #builtins
- tuts/python3/__builtins__/str Linked here; shared tags: #builtins