Reputation: 71
Learning Python, trying to read NASA program. Why is it show=True while defining function? Are we allowed to initialize variable this way? I don' see any use of it.
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)
Thank you everyone for your help.
Upvotes: 1
Views: 4782
Reputation: 160
So yeah, all the answers are right. Basically you can call that function with just one argument... "Show" will just be True.
Upvotes: 0
Reputation: 76
This is Python's syntax for default arguments. If no value is passed for the second argument to visualizeDomain()
, it will automatically be assigned a value of True
. (See https://docs.python.org/2/tutorial/controlflow.html#default-argument-values)
Upvotes: 5