1

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.

2
  • docs.python.org/2/tutorial/… Commented Jan 19, 2015 at 4:37
  • it's passed to s.visualize() on the fourth line Commented Jan 19, 2015 at 4:46

2 Answers 2

5

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)

Sign up to request clarification or add additional context in comments.

1 Comment

And note that it is evaluated when defining the function, so if the value is mutable and you change it inside the function, the change holds for the next invocation of the function. Doesn't apply in this case since True is immutable.
0

So yeah, all the answers are right. Basically you can call that function with just one argument... "Show" will just be True.

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.