Li *_*per 1 python variables initialization function
学习Python,尝试阅读NASA程序。为什么定义函数时show=True?我们可以这样初始化变量吗?我看不出它有什么用处。
def visualizeDomain(domain, show=True):
'''Draw all the sensors and ground truth from a domain'''
centerMap(domain.center[0], domain.center[1], 11)
for s in domain.sensor_list:
apply(addToMap, s.visualize(show=show))
if domain.ground_truth != None:
addToMap(domain.ground_truth, {}, 'Ground Truth', False)
Run Code Online (Sandbox Code Playgroud)
感谢大家的帮助。
小智 5
这是 Python 默认参数的语法。如果没有为第二个参数传递任何值visualizeDomain(),它将自动分配一个值True。(参见https://docs.python.org/2/tutorial/controlflow.html#default-argument-values)