class PayGildong:
def __init__(self):
self.day = 25
self.__pay = 1000000
def setPay(self, pay):
self.__pay = pay
def getPay(self):
return self.__pay
gd = PayGildong()
gd.day = 14
gd.__pay = 800000
print(gd.__pay, gd.day)
When you do this, it seems that gd.__pay = 800000
should have an error, but I wonder why it is output without an error.
It would be helpful if you refer to the document below.
https://docs.python.org/ko/3/tutorial/classes.html?#private-variables
A "private" instance variable that can only be accessed inside the object does not exist in Python. However, there is a convention that most Python codes follow: names that begin with an underscore (for example, _spam
) should be treated as non-public parts of the API.
© 2024 OneMinuteCode. All rights reserved.