class someDistance(Distance):
def __init__(self, dist_funct_name_str = 'Something Distance', p=2):
self.p = p
Just wanted to ask what the
dist_funct_name_str = 'Something Distance'
does in the definition?
Any help would be greatly appreciated!
3 Answers 3
It is used to define the default value of the variable dist_funct_name_strin case when no value is passed for it when the object someDistance was invoked.
example:
In [69]: def func(a,b=2): # b has default value of 2
....: print a,b
....:
....:
In [70]: func(1) # no value passed for b ,so it is equal to 2
1 2
In [71]: func(1,5) # 5 is passed for b, so b=2 is neglected
1 5
Comments
Both dist_funct_name_str and p are called default values. If these values aren't set when __init__ is called, then these default values are used instead.
They also occur on other functions as well - not just __init__.
Comments
dist_funct_name_str = 'Something Distance'
Is a "default parameter" passed to the init function. It's basically the parameter used by default of a user or coder has not passed any arguments to a function.
You can read up a bit more on this here: http://effbot.org/zone/default-values.htm and I also recommend this: http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/ .
I've run into the same thing not long ago.