0
class Test:
    def __init__(self):
        print('Object reference:', id(self))
        print('Class object reference', id(Test))


t = Test()

Object reference: 2170838573008

Class object reference: 2170806511808

3 Answers 3

1

It is not the same as class name. Everything is an object in Python. Classes are, and their instances, too. Even modules, and functions, just everything.

Sign up to request clarification or add additional context in comments.

Comments

1

Class Name is not same as class object. When you create an instance of class that time you create an object for that class. In your case t is a Object of class Test.

Almost everything is object in python. So as your class is a type of object.

class Test:
    def __init__(self):
       print('Object reference:',id(self))
       print('Class object reference',id(Test))


t = Test()  // Here t is object of class Test.

Comments

0

when you use class keyword, you are actually creating an instance of type type. Classes are instances themselves.

class Test:
    pass

print(isinstance(Test, type))  # True
print(type(Test))              # <class 'type'>

here, Test is just a label in your global namespace, which points to this instance you have created.

Now when you call your class, here Test, you are creating an instance of it. self inside your class, points to this object (instances of your class).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.