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

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 520

Subscribe to our Newsletter

Subscribe to our newsletter and receive all latest projects...

Leave a Reply

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