python function: Default parameter: Retries=4this form of Def ASK_OK (prompt, retries=4, complaint='Yes or no, please!'): whileTrue:ok=raw_input (Prompt)ifOkinch('y','ye','Yes'): returnTrueifOkinch('N','No','NOP','Nope'): returnFalse Retries= Retries-1 ifRetries <0: Raise IOError ('refusenik User'When print complaint is called: only the necessary parameters are given: Ask_ok ('Do you really want to quit?') gives an optional parameter: ASK_OK ('OK to overwrite the file?',2) or give all the parameters: Ask_ok ('OK to overwrite the file?',2,'Come on, only yes or no!'characteristics of default parameters: Important Warning: The default value is only assigned once. This makes it different when the default value is a Mutable object, such as a list, a dictionary, or an instance of most classes. For example, the following function accumulates (before) the arguments passed to it during subsequent calls: Def F (A, L=[]): L.append (a)returnL print F (1) Print F (2) Print F (3This will print: [1] [1,2] [1,2,3] If you do not want to share the default values in subsequent calls, you can write functions like this: Def f (A, L=None):ifL isnone:l=[] L.append (a)returnL
Learning website:
Http://docs.pythontab.com/python/python3.4/introduction.html#tut-numbers
[Python function learning Article] default parameters