Skip to content

Python print object type | Example code

  • by

Use type() function to get object type and then print it using a print() function in Python. Pass the object as argument into type() built-in and it returns type of the given object.

The type() function can be used in two ways:-

type(object)
type(namr, bases, dict)

Example print type of object Python

simple example code if the input is a string, you will get the output as , for the list, it will be , etc.

type() function With a Single Object Parameter

a = 15
txt = "EyeHunts"
lst = [1, 2, 3]

print(type(a))
print(type(txt))
print(type(lst))

Output:

Python print object type

Using multiple parameters in type() function

Passing object with name, bases, and dict Parameters.

o1 = type('Hello', (object,), dict(a='Foo', b=12))

print(type(o1))

Note: Use the isinstance() function checks if the object is an instance or subclass of classinfo class.

Read here: Python isinstance() Function

Do comment if you have any doubts or suggestions on this Python object topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *