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

PythonServer Side ProgrammingProgramming

The following code shows how to get the class name of the instance in question.

Example

class Number:
    def __init__(self, number):
        self.number = number
n1 = Number(1)
print n1.__class__
print n1.__class__.__name__

Output

This gives the output

__main__.Number
Number
raja
Published on 23-Jan-2018 11:53:56
Advertisements