Come up early in the company to write a blog, I was also drunk
This blog is mainly about Python's built-in functions:
Next, we'll explain 4 built-in functions:
Apply ():
#!-*-coding:utf-8-*-
' Created on
2015-4-7
@author: huangpeng03
Apply can implement a function that
invokes a variable argument list. To store the parameters of a function in a tuple or sequence
'
def sum (x=1,y=2): return
x+y
print apply (sum, (7,))
Console
9
Filter ():
#!-*-coding:utf-8-*-
'
Created
on 2015-4-7 @author: huangpeng03 filter
() can be filtered to touch a sequence, Whether the result returned by a custom function parameter is
' true ' to filter and return the processing result
'
def func (x):
If x>0: Returns
x
print Filter (Func, Range ( -9,10))
Console
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Reduce ():
#!-*-coding:utf-8-*-
' Created on
2015-4-7
@author: huangpeng03
Continuous processing operation '
def sum (x,y): Return x+y print reduce (sum
, Range (0,10)) print reduce (sum,
range (0,10), ten)
print reduce (sum, range ( 0,0), 10)
Map ():
#!-*-coding:utf-8-*-
'
Created
on 2015-4-7 @author: huangpeng03
map can perform the same operation on each element of multiple sequences. And make up the list returns
'
def Power (x): Return
x**x
print map (power,range (1,5))
def power2 (x,y):
return x**y
Print map (power2,range (1,5), range (5,1,-1))