I have these two ways of setting default values of a parameter in an object: First one:
class Test():
Weight = 12.5
def __init__(self, weight = Weight):
self.weight = weight
Testing = Test()
print("First testing: {}".format(Testing.weight))
and second one:
class Test2():
Weight = 12.5
def __init__(self, weight = None):
if weight is None:
self.weight = Test2.Weight
Testing2 = Test2()
print("Second testing: {}".format(Testing2.weight))
Both result in expected format that they will print 12.5. My question is, are these ways equivalent, is one of them faster than the other (my personal tip is that the first one will take less time to execute)? Which one do you prefer? and Is there any other maybe better way? Thank you very much