Type function
Python’s type() function returns an object’s type when called with one argument and can create a class when called with class-construction arguments.
The Quick Python Book, Fourth Edition
The Python type function returns an object's type or creates a new type when called with class-construction arguments.
- How it is used
- Uses type to inspect objects, identify classes, and support runtime type checks.
- How deep it goes
- Explains returned type objects, instance inspection, inheritance metadata, and validation use, but does not develop class construction through type.
- Examples
- Demonstrates integers, lists, user-defined instances, inheritance, and a TypedList that enforces homogeneous elements.
- What you can do after
- Diagnose object and class relationships, then apply captured types in runtime validation.
Read how The Quick Python Book, Fourth Edition explains type function →
Python How-To
type is a Python built-in function that returns the type of an object.
- How it is used
- Uses runtime type inspection to make functions accept and process different input forms.
- How deep it goes
- Explains the return value and a worked type-based branch, while deferring superclass-friendly checks to isinstance.
- Examples
- Demonstrates integers, lists, reassigned variables, assertions, and a task-filtering function.
- What you can do after
- Apply it via Python’s built-in type function to inspect values and branch behavior for supported input types.
Get Programming: Learn to code with Python
A Python built-in function that returns the type of an object.
- How it is used
- Checks an object's data type in the Python console when its type is uncertain.
- How deep it goes
- Defines type() and demonstrates console checks, but does not explain its internal implementation.
- Examples
- Uses type(3) and type("wicked") to identify integer and string values.
- What you can do after
- Evaluate values in the console to identify their data types.
Read how Get Programming: Learn to code with Python explains type function →
Also covered in
What to know first
- objectAn object is a distinct computational entity or value represented with associated data, structure, identity, or behavior.
- PythonPython is a high-level, general-purpose, dynamically typed programming language with readable syntax and support for multiple programming paradigms.
- classA class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating instances.
Related concepts
- atomic typemeasures · An atomic type is a type whose supported accesses and operations are indivisible with respect to concurrent execution and provide defined synchronization semantics.
- __class__ attributeequivalent to · The __class__ attribute references the class object associated with a Python object.
- isinstancecontrasts with · isinstance is a Python built-in function that tests whether an object is an instance of a specified class or tuple of classes, including subclasses.
- reflectionused by · Reflection is a programming-language or runtime capability for inspecting and sometimes manipulating program types, members, values, or metadata during execution.
- objectuses · An object is a distinct computational entity or value represented with associated data, structure, identity, or behavior.
- classproduces · A class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating instances.
Questions about type function
What is type function?
Python’s type() function returns an object’s type when called with one argument and can create a class when called with class-construction arguments.
Which Manning books explain type function?
The Quick Python Book, Fourth Edition, Python How-To and Get Programming: Learn to code with Python.
What should I know before learning type function?
Manning books that teach type function usually introduce object, Python and class first.
What is the difference between type function and isinstance?
Python’s type() function returns an object’s type when called with one argument and can create a class when called with class-construction arguments. isinstance is a Python built-in function that tests whether an object is an instance of a specified class or tuple of classes, including subclasses.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


