Find the Class of a Python Object

Sometimes you are working with an object in Python, and because Python is not a strongly typed language, you don’t always know which class it is an implementation of. A quick way to find out is to use the type method, which can be invoked on any object and gives you a String representation of the class.

obj = "abc"
type(obj)

This would output “<type ’str’>.”

Leave a Reply