optional arguments in initializer of python class
问题 I was wondering if anyone had any good ways of quickly explaining how to efficiently and pythonically create user defined objects with optional arguments. For instance, I want to create this object: class Object: def __init__(self, some_other_object, i, *j, *k): self.some_other_object = some_other_object self.i = i # If j is specified, assume it is = i if(j==None): self.j = i else: self.j = j # If k is given, assume 0 if(k==None): self.k = 0 else: self.k = k Is there a better way to do this?