How does it know what values to use for each parameter?
Answer
Before you call the function, the program has no way of knowing what the values will be, unless you set a default by typing parameter_name=0, for example. That would set the default value of parameter parameter_name to 0.
Otherwise it simply assigns parameter values with the arguments provided when the function is called. With power(), the function defined and used in this exercise, we provide it two arguments: a base and an exponent, in that order. If we did power(10, 2), then 10 would be assigned to base, and 2 assigned to exponent to be used throughout the function with those values.
same question here.
in previous exercises it was stressed and presented as a matter of fact that each function has to return something to follow the control flow construct.
anyone please?
if no return keyword is present, None is implicitly returned
In my personal experience, while learning programming, you learn a concept (like return, or functions) and the true value becomes more apparent once you start building actual programs.
being able to pass data around between functions is so useful, but given you are still learning programming concepts at the moment, a concept learned might not be used in every exercise (like return here, because this exercise doesnât focus on that)
however, somewhere should have been mentioned that None is implicitly returned
We can think of it like that, though it is misleading. No return means no return, not None.
If we poll a return value,
print (foo())
assuming foo() has no return statement, we print None because that is how Python fills in the gap. There is nothing to print so it reaches into its bag of defined objects and retrieves the one associated with ânothingâ => None. JavaScript does the same thing, only with undefined, and Ruby does it with, nil.
There is no return value. Nothing is returned, implicitly or otherwise. It is only the lack of anything that springs Python into action to attempt to print something. If we do this in the interactive shell, and let the console handle the output without using print(), we getâŚ