研究一下
發現主要差異在
實例化之後呼叫函式是否需要帶入自己 self
感覺是很雞肋的功能?
或許是我知識淺薄
不懂這功能的用意吧
程式碼示範:
class A(): myWord = 'i am a' @staticmethod def static_B(): print("i am b") def no_static_C(): print("i am c") def no_static_D_self(self): print("i am d") nA = A() #實例化 nA.static_B() #pass nA.no_static_D_self() #pass nA.no_static_C() #報錯 需要帶入自己 輸出: TypeError: no_static_C() takes 0 positional arguments but 1 was given
留言板
歡迎留下建議與分享!希望一起交流!感恩!