classClassA(object):def__init__(self):print"Hello Python!"def__del__(self):print"Goodbye Python!"def__str__(self):return"This is Class A"defsay_hello(self,words):print"Hello,",wordsdefdo_nothing(self):passa=ClassA()a.say_hello("eddie")printa# 執行結果HelloPython!Hello,eddieThisisClassAGoodbyePython!
classClassB(object):def__private_method(self):print"this is for personal only"defget_private_method(self):self.__private_method()b=ClassB()b.__private_method()# 執行結果# AttributeError: 'ClassB' object has no attribute '__private_method'b.get_private_method()# 執行結果# this is for personal only