python basis of built-in functions

1  Print (All ([0, 1, 2])) # Falsee iterables each to True returns True, otherwise False. Because the list of all returns True 0; None iterator object contains also returns False, the rest are True 
2  Print (the any ([None,. 1])) # True iterables have any element corresponding to a Boolean true is the true determination 
3  Print (bin (255)) # the binary converted into decimal numbers 
. 4 hex (10) # decimal to hexadecimal 
. 5  Print (OCT (10)) # decimal convert octal 
. 6  Print (BOOL (None)) # determine a true or false Boolean variable 0 None is false and the rest are false 
7 a callable (1) # determine whether the object can be called, the function name is callable, making up a list of calls is 
8  Print (CHR (97)) # a a number into a corresponding code asc-ii
. 9  Print (the ord ( " A " )) # 97 with opposite functions chr 
10  # the compile python code can be converted to a string, assign it to a variable, and then use the exec execute 
. 11 code = " for I in Range (. 5) : Print (I) " 
12 is code_obj = the compile (code, " the error.log " , " Exec " )
 13 is  Exec (code_obj)
 14  # Exec can directly command string when py, eval string value calculation request directly value 
15  Exec (code)
 16 the dir (code) # built-in way to view the object 
. 17  Print (divmod (. 5, 2)) #Divide two numbers, returns a tuple, the first value is the second tuple commercially residue 
18 is  # enmuerate method returns the list tuple cycle, the first cycle to a value tuple list index the second is a value corresponding to the index 
. 19  for index, value in the enumerate ([. 1, 2,. 3 ]):
 20 is      Print (index, value)
 21 is  # filter with two arguments, a first determination condition for the second is iterables the iterables using determination conditions by one filter, the data conditions are met returned to an iterator, usually anonymous functions used simultaneously, anonymous function are judged statement 
22 is  for I in filter ( the lambda n-: n-% 0 == 2, Range (10)): # 0. 4 2. 8. 6 
23 is      Print (I)
 24  # Map two arguments, the first is a function name, the second is iterables; effect will be iterative objects one by one passed to the function, the output is an iterator objects 
25  for I in Map (the lambda n-: 2 n-%, Range (10)): # 0. 1. 1 0 0 0. 1. 1. 1 0 
26 is      Print (I)
 27  # the reduce the map similar to the iterables used function, and then all Returns the value with. Wherein the function must be two parameters, the first two values to the previous iteration object passed as an argument, then the function returns the value assigned to x as the first argument, then take a third value from the iterator as a function of the second iteration of the second argument, recursive sequence 
28  Import functools
 29 RES = functools.reduce ( the lambda X, Y: X * Y, Range (1,10 ))
 30  Print (RES)
 31 is frozenset () # the object becomes a non-modified state 
32  Print (Globals ()) # returns the current program of all variable and its current value k: v format 
33 is about locals () # and the corresponding global function which function is obtained with this method local variables information 
34 is X =. 1; ID (X)# Returns the memory address x 
35  Print (max ([. 1,. 3,. 5, 45])) # Returns the list of maximum 
36 min ([. 1,. 3,. 5, 45]) # with the corresponding max, returns a list of the minimum 
37  for I in the reversed ([. 1,. 3,. 5, 45]): # list reversed to return an iterator 
38 is      Print (I)
 39  Print (round (1.2345,. 3)) # 1.234 decimal floating-point number takes 
40 = {. 1 dict1: 2, 55:. 6, 34 is: 2,. 3:. 5 }
 41 is  Print (the sorted (dict1)) # the dictionary sorted and output to a key within the list of 
42 is  Print (the sorted (dict1.items ()) ) # the dictionary key: value is converted into a tuple, and in accordance with a first element of the tuple sort result is output to a list 
43 Print (SUM ([. 1, 2,. 5])) # listing summation 
44 is A = [. 1, 2,. 3,. 4 ]
 45 B = [ " A " , " B " , " C " , " D " ]
 46 is  for var in ZIP (a, B): # the two combined values corresponding to the list as a tuple, which returns tuples iterator, iterator length equal to the length of the small list 
47      Print (var)
 48  
49  __import__ ( " Time " ) # is equivalent to import time, it can be introduced using the object name as an argument string format

 

Guess you like

Origin www.cnblogs.com/flags-blog/p/11961003.html