[Python] Visibility

2023. 1. 27. 19:16·기타

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  (1) 2023.01.27
[Python] decorate  (0) 2023.01.27
[Python] polymorphism  (0) 2023.01.27
[Python] inheritance  (0) 2023.01.27
[Python] class  (1) 2023.01.27
'기타' 카테고리의 다른 글
  • [Python] inner function
  • [Python] decorate
  • [Python] polymorphism
  • [Python] inheritance
생각 기록실
생각 기록실
AI(LLM)와 서비스 기획을 공부하며 작성하는 기술 블로그입니다. (feat. 영화리뷰를 곁들인..)
    반응형
  • 생각 기록실
    이러쿵 저러쿵
    생각 기록실
  • 전체
    오늘
    어제
  • 링크

    • Github
    • LindeIn
    • 분류 전체보기 (115)
      • 이러쿵 저러쿵 (5)
      • 정보통계 (7)
        • 데이터마이닝 (2)
        • 금융공학 (4)
      • IT (26)
        • Python (10)
        • AWS (5)
        • Github (2)
        • Project (8)
      • 리뷰 (29)
        • 영화 (22)
        • 책 (7)
      • 기타 (48)
  • hELLO· Designed By정상우.v4.10.3
생각 기록실
[Python] Visibility
상단으로

티스토리툴바