liveBook · Manning

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.

How 3 Manning books explain it

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.

Read how Python How-To explains type function →

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

Related concepts

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.