class someDistance(Distance):
def __init__(self, dist_funct_name_str = 'Something Distance', p=2):
self.p = p
只是想问一下
dist_funct_name_str = 'Something Distance'
在定义中吗?
任何帮助将不胜感激!
最佳答案
它用于定义变量dist_funct_name_str
的默认值,以防在调用对象someDistance
时没有为其传递任何值。
示例:
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
关于python - python 中定义中的类和字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13102717/