Menu Close

How to get the class name of an instance with Python?

Sometimes, we want to get the class name of an instance with Python.

In this article, we’ll look at how to get the class name of an instance with Python.

How to get the class name of an instance with Python?

To get the class name of an instance with Python, we can use the __name__ property.

For instance, we write

type(x).__name__

to get the __name__ attribute of the class that’s used to create variable x.

We get the class that’s used to create x with type.

How to get the class name of an instance with Python?

To get the class name of an instance with Python, we can use the __name__ property.

Posted in Python, Python Answers