The senior python (a) --- the type of function

function

The variable parameter function

 

Keyword arguments

 

Anonymous function

 

Partial function

 

Closure

 

 

 

 


Decorator

  Under a reference notes: https: //www.cnblogs.com/TMMM/p/11395710.html 

Builder

  Builder:

  The logic to generate a data storage container. To make up a list of formula drawbacks.

  Builder saves memory, when the generated data is not generated immediately stored in the memory, a storage out a rather

  The distinguished list of formula:

  List of Formula can quickly generate a batch of data is stored in memory. There is a list of Formula drawbacks:

  If you generate a lot of data, but only data in front of some, this time using a list of formula is very wasteful of memory

  Generator has generated the data in two ways:

  1. Formula list in parentheses into brackets (source data generated by the data filter)

  1. Statement similar to the method needs to call the method every time when the need to return data generated. Instead of using return returns [as return function is ended] using the yield instead of return to return the data generator

  Obtaining data generator

  The next by a method of extracting a data from a builder

  Reuse the data has been removed next acquired data acquired is a data acquisition will not repeat the same data

1  # generator generating a first way and data acquisition 
2 GE = (NUM for NUM in Range (1,1000 ))
 . 3  Print (GE) # which results Type: <Object Generator <genexpr> AT 0x106b9c480> 
. 4 value = Next (GE)
 . 5  Print (value) # result is: 1. Performed next (ge) Again, the result is: 2 
. 6  # get the first 10 data 
. 7  for _ in Range (10 ):
 . 8      value = next (ge)
 . 9      Print (value)
 10  '' ' 
. 11  traversed when needed will correspond to the value assigned to the variable to afford a variable name to store data
 12 When traversed only for obtaining the number of cycles, so as not to obtain the sequence of elements can be used in the placeholder variable _
 13  '' ' 
14  
15  # generator and generating a second embodiment acquires data 
16  DEF the get_value ():
 17      for i in the Range (1,1000 ):
 18          yield i # here is not the end of the function, if the same level of yield and there is a statement will be executed, but is executed when the second acquisition of 
19 GE = the get_value ()
 20 is  Print (GE) # which results type: <Object Generator <genexpr> AT 0x106b9c480> 
21 is value = Next (GE) 
 22 is  Print (value)

  Note: When the data generated which take complete, go get the data, returns wrong

Iterator

  Traversal sequence : for variable in sequence

 Iterator : is the equivalent of another embodiment traversal sequence, a movement of an iterative method of access to data by the next

      If you want to use a sequence iterator premise of this sequence is iterative

  collections module: Iterator iterator ---

          Whether Iteratable --- verification sequence can iterate

. 1  from Collections Import the Iterable, the Iterator
 2  
. 3  # Verify whether the specified data type is iterative 
. 4 RES = the isinstance (10 , the Iterable)
 . 5  Print (RES) # Results: False. Integer is not iterative 
. 6  
. 7 RES = the isinstance ( ' 10 ' , the Iterable)
 . 8  Print (RES) # Results: True. String type is iterative 
. 9  
10 RES = the isinstance (( ' 10 ' ), the Iterable)
 . 11  Print (RES) # Results: True. Tuple type iterative is 
12 is  
13 isthe isinstance = RES ([ ' 10 ' ], the Iterable)
 14  Print (RES) # Results: True. Iterative list type is 
15  
16 RES = the isinstance ({ ' 10 ' }, the Iterable)
 . 17  Print (RES) # Results: True. Iterative type is set 
18 is  
. 19 RES = the isinstance ({ ' 10 ' : 10 }, the Iterable)
 20 is  Print (RES) # Results: True. Dictionary type is iterative 
21  "" " 
22  Iterable this type of verification is: all of the sequences are possible iteration [traverse], for in traverse
 23  sequences can be used for in traverse, and can not necessarily be iterative device traversal. iterates over a method of using a next iteration
24  generators --- can be used next to iterate --- you can use an iterator iteration.
25  lists can be used for in --- --- but not a traverse is iterating
 26  "" " 
27  
28  # To iterate through the list using the iterator type requires that the ITER (serial) conversion, 
29  # is converted into iterator iterator type can use an iterative method next traverse 
30 the List0 = [12,34,64,76,34,5,86 ]
 31 is IT = ITER (the List0)
 32 value = next (IT)
 33 is  Print (value) # results: 12 is 
34 value = Next (IT)
 35  Print (value) # results: 34

 

Guess you like

Origin www.cnblogs.com/TMMM/p/11423392.html