Define a class with optional argument in Python

前端 未结 3 670
迷失自我
迷失自我 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:41

    Try defining a default argument, like so.

    class class1():
        def setdata(self,value1, value2='000'):
            ...
    

提交回复
热议问题