Jan Lamb learned, Wu Pei Qi told Day16 finish

Nested functions

foo () () () ==== foo () >>> gxr gxr () >>> wsb wsb () >> function execution wsb

Lambda line function, to do simple logic calculation.

func=lambda x,y,z:x+y+zprint(func(1,2,3))
===6

function map each element of the processing sequence, the result is a 'list', the 'list' and the number of elements in the same position as the original

= MSG 'linhaifeng' 
Print (List (Map (the lambda X: x.strip ( "n"), MSG))) in the list of "n" side ","
===['l', 'i', '', 'h', 'a', 'i', 'f', 'e', '', 'g']
The filter function through each element of the sequence, each element of the Boolean value is determined, if the stay is True
= MSG 'linhaifeng' 
Print (List (filter (the lambda n-: n.strip ( "n"), MSG))) in the list of "n" removed
=====['l', 'i', 'h', 'a', 'i', 'f', 'e', 'g']  
The reduce function        processing a sequence, then the merging operation sequence
from functools import reduce
num_l=range(1,5)
print(reduce(lambda x,y:x*y,num_l,1))      1*1*2*3*4
print(reduce(lambda x,y:x*y,num_l))        1*2*3*4
print(reduce(lambda x,y:x+y,num_l,1))      1+1+2+3+4
print(reduce(lambda x,y:x+y,num_l))        1+2+3+4

24
24
11
10

There are other built-in functions

abs (-1) >> 1 the absolute value

all ([1,2]) >>> Flase list which are all Flase is Flase 

any ([0, '']) >>> True list which are all True True is 

bin (3) >>>> 0b11 binary conversion 

bool () Boolean value

name = 'Hello'
Print (bytes (name, encoding = 'UTF-. 8')) bytes variable byte string >>>>

After bytes (name, encoding = 'utf-8'). Decode ( 'utf-8') with the name decoded into utf-8 bytes, and then encoded into characters utf-8

chr (80) is converted into the decimal ASCII characters

dir () method of obtaining a print target

divmod (11,3) >>>> I 2 (3,2) 11/3 = List 3

= {DIC 'name': 'Alex'}
dic_str = STR (DIC)
Print (dic_str) converted to the character dictionary

eval (dic_str) characters into dictionary

eval ( '1 + 1') of the string out of the calculated

hash () can not change the type of a file into the Hash do After checking hash hash unchanged, no modification is equal to

hex () 16 hex

act () 8-ary

isinstance ( 'abc', str) Analyzing 'abc' is not a result str bool

globals () a global variable  

about locals () the local variables 

= L [1,3,100,-1,2]
Print (max (L)) maximum
print (min (l)) Min

Had previously been learned here stuck .. ,, excited to learn the next lesson not heard of the

Guess you like

Origin www.cnblogs.com/gxrwsb/p/11569921.html