2017-04-25 46 views
0

使用pycharm社區軟件,我創造了這個代碼使用Python類錯誤pycharm社區

Class calculator : 
      def addition (x, y) 
       added = x+y 
        Print (added) 
Calculator1 = calculator() 
Calculator.addition(3,5) 

我得到這個錯誤

calculator.addition(3,5) 
TypeError: substration() takes exactly 2 arguments (3 given) 

回答

0

您應在addition方法如下面添加關鍵字self嘗試

class calculator: 
    def addition (self, x, y): 
     added = x+y 
     print (added) 

Calculator = calculator() 
Calculator.addition(3,5) 
+0

感謝它的工作 – freeyooh