<> Built in functions

One , Mathematics related
abs(a) : Get the absolute value .abs(-1) max(list) : seek list Maximum .max([1,2,3]) min(list) :
seek list minimum value .min([1,2,3]) sum(list) : seek list Sum of elements . sum([1,2,3]) >>> 6 sorted(list)
: sort , Return sorted list. len(list) : list length ,len([1,2,3]) divmod(a,b): Get quotient and remainder .
divmod(5,2) >>> (2,1) pow(a,b) : Get the power .pow(2,3) >>> 8 round(a,b) :
Gets the decimal number of the specified number of digits .a Represents a floating point number ,b Represents the number of digits to keep .round(3.1415926,2) >>> 3.14 range(a[,b]) :
Generate a a reach b Array of , Left closed right open . range(1,10) >>> [1,2,3,4,5,6,7,8,9]
Two , Type conversion
int(str) : Convert to int type .int('1') >>> 1 float(int/str) : take int Type or character type to floating point type .float('1')
>>> 1.0 str(int) : Convert to character type .str(1) >>> '1' bool(int) : Convert to boolean type . str(0) >>> False
str(None) >>> False bytes(str,code) : Receives a string , And the format to be encoded , Returns a byte stream type .bytes('abc',
'utf-8') >>> b'abc' bytes(u' Reptile ', 'utf-8') >>> b'\xe7\x88\xac\xe8\x99\xab'
list(iterable) : Convert to list. list((1,2,3)) >>> [1,2,3] iter(iterable)： Returns an iteratable object .
iter([1,2,3]) >>> <list_iterator object at 0x0000000003813B00> dict(iterable) :
Convert to dict. dict([('a', 1), ('b', 2), ('c', 3)]) >>> {'a':1, 'b':2, 'c':3}
enumerate(iterable) : Returns an enumeration object . tuple(iterable) : Convert to tuple. tuple([1,2,3])
>>>(1,2,3) set(iterable) : Convert to set. set([1,4,2,4,3,5]) >>> {1,2,3,4,5}
set({1:'a',2:'b',3:'c'}) >>> {1,2,3} hex(int) : Convert to 16 Base system .hex(1024) >>> '0x400'
oct(int) : Convert to 8 Base system . oct(1024) >>> '0o2000' bin(int) : Convert to 2 Base system . bin(1024) >>>
'0b10000000000' chr(int) : Convert numbers to corresponding ASCI Code character . chr(65) >>> 'A' ord(str) :
transformation ASCI The characters are the corresponding numbers . ord('A') >>> 65
Three , Function related
eval() : Execute an expression , Or string as an operation . eval('1+1') >>> 2 exec() : implement python sentence .
exec('print("Python")') >>> Python filter(func, iterable) :
By judging the function fun, Select the qualified elements . filter(lambda x: x>3, [1,2,3,4,5,6]) >>> <filter object at
0x0000000003813828> map(func, *iterable) : take func For each iterable object . map(lambda a,b:
a+b, [1,2,3,4], [5,6,7]) >>> [6,8,10] zip(*iterable) : take iterable Group merging . Return a zip object .
list(zip([1,2,3],[4,5,6])) >>> [(1, 4), (2, 5), (3, 6)] type()： Returns the type of an object . id()：
Returns the unique identity value of an object . hash(object)： Returns the name of an object hash value , With the same value object With the same hash value . hash('python')
>>> 7070808359261009780 help()： Call the built-in help system . isinstance()： Determine whether an object is an instance of the class .
issubclass()： Determine whether a class is a subclass of another class . globals() : Returns the dictionary of the current global variable . next(iterator[,
default]) : Receives an iterator , Returns the value in the iterator , If set default, After traversing the elements in the iterator , output default content .
reversed(sequence) ： Generate an iterator that reverses the sequence . reversed('abc') >>> ['c','b','a']
Four , Examples of several functions

1,map Function maps the specified sequence based on the function provided .
map The definition of the function is as follows ： map（function,iterable,……） The first argument is the name of the function , The second parameter is a container or iterator that supports iteration .
map The function is ： Called separately for each element in the parameter sequence function function , Save the result returned by each call as an object .
func=lambda x：x+2 result=map（func,【1,2,3,4,5】） print（list（result））
Execution process ：

2,filter function

filter Function performs a filtering operation on the specified sequence
filter The function is defined as follows ： filter（function,iterable） The first argument is the name of the function , The second parameter represents the sequence , Container or iterator supporting iteration .
Sample code
func=lambda x：x+2 result=filter（func,【1,2,3,4,5】） print（list（result））
Execution process ：

3,reduce function

reduce The function accumulates the elements in the parameter sequence
reduce The definition of the function is as follows ： reduce（function,iterable【initializer】） .function Is a function with two arguments
.sequence Is an iterative object .initializer Represents a fixed initial value
Sample code
func=lambda x,y：x+y result=reduce（func,【1,2,3,4,5】） print（list（result）
be careful ：function Function cannot be None
stay python3 in ,reduce Function has been removed from the global namespace , Now placed in fucntools In the module , It needs to be introduced before use , The format is as follows ： from
fucntools import reduce

Technology