Getting the class name of an instance in Python?

Better Stack Team
Updated on February 3, 2023

You can use the built-in type() function to get the class name of an instance in Python. For example:

class MyClass:

my_instance = MyClass()

This will output MyClass. You can also use the __class__ attribute on the object which returns the class of the instance.

class MyClass:

my_instance = MyClass()

This will also output MyClass.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack