「Python入門」アンダースコア”_”のサンプル

pythonコード
class A(object):

def __method(self):
print(“Input a method in class A")

def method_x(self):
print(“Input another method in class A\n")

def method(self):
self.__method()
self.method_x()

class B(A):

def __method(self):
print(“Input a method in class B")

def method_x(self):
print(“Input another method in class B\n")

if __name__ == '__main__’:

print(“テストケース 1:")
a = A()
a.method()

b = B()
b.method()

print(“テストケース 2:")
# a.__method()
a._A__method()

実行結果:
テストケース 1:
Input a method in class A
Input another method in class A

Input a method in class A
Input another method in class B

テストケース 2:
Input a method in class A

Python

Posted by arkgame