calling a function from class in python - different way

后端 未结 5 1419
别那么骄傲
别那么骄傲 2021-02-04 09:54

EDIT2: Thank you all for your help! EDIT: on adding @staticmethod, it works. However I am still wondering why i am getting a type error here.

I have just started OOPS a

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 10:59

    class MathsOperations:
        def __init__ (self, x, y):
            self.a = x
            self.b = y
        def testAddition (self):
            return (self.a + self.b)
    
        def testMultiplication (self):
            return (self.a * self.b)
    

    then

    temp = MathsOperations()
    print(temp.testAddition())
    

提交回复
热议问题