Default Argument Values: a simple demo,argumentvalues,# specify a


# specify a default value for one or more arguments. # This creates a function that can be called with fewer arguments than it is defined # to allow. For example:def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):    while True:        ok = raw_input(prompt)        if ok in ('y', 'ye', 'yes'): return True        if ok in ('n', 'no', 'nop', 'nope'): return False        retries = retries - 1        if retries < 0: raise IOError, 'refusenik user'        print complaint#This function can be called either like this: ask_ok('Do you really want to quit?') # or like this: ask_ok('OK to overwrite the file?', 2) 

评论关闭