• Source
    1. class MyClass:
    2. def __init__(self):
    3. self.__field = 123
    4. def __method(self):
    5. print("this is private method 2.")
    6.  
    7. c = MyClass()
    8. # {instance}._{ClassName}__{private_member_name} の書式でアクセスできてしまう
    9. print(str(c._MyClass__field))
    10. c._MyClass__method()
    11.  
    12. # ふつうに参照するとエラーになる
    13. #print(str(c.__field))
    14. #c.__method()