[Python] Same memory address for every object is created from a class

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I have a class. created a two different object from the class. if we print the object it should return same address. Could anyone explain it is possible or not.

    class A:
    def __init__(self):
    pass

    obj1=A()
    obj2=A()
    print(obj1)
    print(obj2)


    Output: <main.A object at 0x000001AEE78F3A90> <main.A object at 0x000001AEE79E54F0>

    Note: Both should print same address of class A. (It is an interview question.)

    Continue reading...

Compartilhe esta Página