Visibility는
클래스 내부에서 정의된 멤버 변수와 메소드의 접근 권한을 의미합니다.
예시코드
class MyClass:
def __init__(self):
# public 멤버 변수
self.public_variable = 10
# private 멤버 변수
self.__private_variable = 20
# public 메소드
def public_method(self):
print(self.public_variable)
# private 메소드
def __private_method(self):
print(self.__private_variable)
# public 멤버 변수 접근 가능
my_instance = MyClass()
print(my_instance.public_variable)
# private 멤버 변수 접근 불가
print(my_instance.__private_variable)
# public 메소드 호출 가능
my_instance.public_method()
# private 메소드 호출 불가
my_instance.__private_method()
반응형
'기타' 카테고리의 다른 글
[Python] inner function (0) | 2023.01.27 |
---|---|
[Python] decorate (0) | 2023.01.27 |
[Python] polymorphism (0) | 2023.01.27 |
[Python] inheritance (0) | 2023.01.27 |
[Python] class (0) | 2023.01.27 |