Confused about scope and positional argument

def repeat_stuff(stuff, num_repeats = 10):
return stuff*num_repeats

song = repeat_stuff(repeat_stuff("Row ", 3) + "Your Boat. ")

I’m wondering why the value 3 doesn’t get reused in the second function of repeat_stuff. Could somebody give me a thorough explanation of what is going on in this script?


why would we want this?

if we don’t provide any argument, the default value (10) is used. If we want our song to consist of 10 lines (which seems to be the task at hand), we don’t need to provide any argument, that is the advantage of a parameter with a default value

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.