I am very new to Python. Here is some test code:
class Test():
def __init__(self,num,option):
self.__num = num
self.option = option
def getNum(self):
return self.__num
def getOption(self):
return self.option
my_num = Test(77,1)
print(my_num.getNum()) // 77
print(my_num._Test__num) // 77
print(my_num.__num) // Attribute error
My question is:
Why my_num.getNum() returns 77?
Why self.__num through getNum has value and my_num.__num returns error?
self in self.__num points to my_num, isn't it? Since __num is a private property, how is it accessible through self whereas self points to an object?
#getNumis a method of the class, so of course it can directly access attributes by their actual name.