nums = [1,2,3,4,5]
map function
map (function sequences)
The map is a value in the array performs a certain process, the value of the processed into a new array, and returns the new array.
map(lambda x:x++2,[1,2,3,4])
It returns iterables
for i in map(lambda x:x++2,[1,2,3,4]):
print(i)
3
4
5
6
def test(x):
if(x>=1):
x = x - 1
return x+test(x)
else:
return 0
for i in map(test,[1,2,3,4]):
print(i)
0
1
3
6
>>> list(map(test,[1,2,3,4]))
[0, 1, 3, 6]
filter function
filter through some sort of filter criteria to meet the requirements of an array value into a new array and returns the new array
filter (function sequences)
Come up with a Boolean value
>>> list(filter(lambda x:x.startswith("a"),["aa","bb","abc","abd"]))
['aa', 'abc', 'abd']
def test1(x):
if(len(x) > 2):
return True
else:
return False
>>> list(filter(test1,["aa","bb","abc","abd"]))
['abc', 'abd']
reduce function
reduce a processing sequence, the merging operation sequence
>>> def add(x, y):
return x+y
reduce(add, [1,2,3,4])
10
abs () absolute value
all () to do a Boolean value out of budget
bool bool value is converted to
bytes("aa',encoding="utf-8").decode("utf-8")
>>> bytes("选项",encoding="utf-8")
b'\xe9\x80\x89\xe9\xa1\xb9'
bytes(b'\xe9\x80\x89\xe9\xa1\xb9').decode("utf-8")
'选项'
chr () ascii code
dir () View
divmod(10,3)
(3,1) take the quotient modulo
eval () function
Simple expression
print(eval('1+2'))
3
String turn Dictionary
print(eval("{'name':'linux','age':18}")
{'name':'linux','age':18}
Global Variables
globals()
Local variables
locals()
max () maximum
min () Min