Computer >> Computer tutorials >  >> Programming >> Python

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


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