Define a class with optional argument in Python

前端 未结 3 671
迷失自我
迷失自我 2021-02-14 14:43
class class1():
    def setdata(self,value1, value2):
    self.data = value1+value2
def display(self):
    print(self.data)

For the above code, when I

3条回答
  •  遥遥无期
    2021-02-14 15:40

    class class1:    
        def setdata(self,value1, value2=456):
            self.data = value1+value2
        def display(self):
            print(self.data)
    

    may be this solves your problem

提交回复
热议问题