1

How is a(object of F class) is printing the private variable?

    class F:
        def __init__(self):
            self.__y=5
    a=F()
    a.__y=10
    print(a.__y)

The output is 10. I know that the new assignment updated the value of a.__y(or y?). But, I'm not able to understand how y is accessed outside the class. I tried printing IDs of both, they are different. Can someone provide better explanation for this?

0 Answers0