• Source
    1. #!python3
    2. #encoding:utf-8
    3. class TestClass:
    4. def __init__(self):
    5. pass
    6. self._private_field = 100
    7. self.__private_field = 101
    8. def _private_method(self):
    9. print("this is private method 1.")
    10. def __private_method(self):
    11. print("this is private method 2.")
    12.  
    13. if __name__ == "__main__":
    14. c = TestClass()
    15. print(str(c._private_field))
    16. # print(str(c.__private_field))
    17. c._private_method()
    18. # c.__private_method()
    19. print(str(c._TestClass__private_field))
    20. c._TestClass__private_method()
    21.  
    22. c = TestClass()