day 009

day 009

If not os.path.esists(key_word): os.mkdir(key_word)

Confirm that the path exists; when crawling data classification save the downloaded file

function

Function is a separate tool does not reduce the amount of codes

The syntax of the function

def function name; definitions Tool Name - "and the same variable specification ," to achieve the function " function name () before use; (encapsulate internal code by function name def +)

DEF name (): normal writer name ()  # use the function
 
  1. Empty function;

    #TODO: Registration is temporarily not write # to insert a bookmark, 
    Pass # write an empty function accounting positions
  2. parameter;

    Type reference (description) argument (specific values)

    DEF the Add ( X, Y):   # X, Y-type reference return X + Y the Add ( . 1, 2) # 1,2 argument
       
  3. The default type parameters;

    Had been paid value in the definition stage, you can not pay the value at the time of call, it can pay its value to the default value replaced.

     

  4. Keyword argument;

    When calling the function, value pairs in the manner specified through the parameter values, can break position regulating

    You can mix solid position to participate in the keyword argument, but the argument must be key position after the argument, and can not pay duplicate reference value for a type.

  5. Location parameters;

    From left to right a defined type parameters, each value must be delivered, the location argument must correspond therewith.

  6. Return value of the function; return

    After some internal code function result obtained by the processing logic. Need to be, but does not print the result

    return function is a sign of the end

    return return value can be any data type

     

  7. No reference function;

    No argument, no input parameters used directly

    DEF the Add (): Print ( 'fixed content') the Add ()
       

     

  8. There are function parameters

    There are parameters, you must use the input parameters

    defadd(x,y):
       returnx+y
    add(1,2)

     

Defined Functions

Guess you like

Origin www.cnblogs.com/luocongyu/p/11448321.html