Python Program to Get the Class Name of an Instance – 2024

Hey guys, in this blog we will see a Python Program to Get the Class Name of an Instance.

Table of Contents

Example 1: Using __class__.__name__

class Project:
    def name(self, name):
        return name

p = Project()
print(p.__class__.__name__)

Output

Project
  • We can use object.__class__.__name__ to get the class name of the object.

Example 2: Using type() and __name__ attribute

class Project:
    def name(self, name):
        return name

p = Project()
print(type(p).__name__)

Output

Project
  • We can also use type(object).__name__ to get the class name of the object.

Check out our other python programming examples

Leave a Reply

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