1
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

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

0
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.