Section V: function (to be supplemented)

Programming Theory:
process-oriented
object-oriented
functional programming

Programming functions are:
higher-order function:
1, function takes the name of a function
2, the function returns the value contained in

function map each element of the processing sequence, the result is a "list", and the position of the elements of the list as the original
filter through each element of the sequence, each element is determined to give a Boolean value, if it is to stay True down
reduce a processing sequence, the operation sequence is combined
tail call optimization function of
the last step into the recursive function in


the lambda

Map function example
filter function example

For example reduce function

built-in functions:
ABS () takes the absolute value of
all () to test whether all the elements are True, otherwise False

all ( "0") test result is True

any () to test whether all the elements one is True, otherwise False
ASCII
bin
BOOL () Boolean operations
bytes
CHR ()

the ord () is converted into a decimal octal
dict () create a dictionary
the dir
divmod () tab calculates
the enumerate
the eval. 1, extracting data structure string 2, string operations performed

a = "{" cc ": 12}" d = eval (a) the extracted string dictionary
a float
frozenset
hash. 1, the thrust reverser extraordinary hash value 2, hash value of a fixed length
hex decimal convert hexadecimal
oct Decimal turn octal
id see the memory address
isinstance determine the data type is not who object
locals Print the local variables
globals global variables Print

zip (( "a", "b", "c") (1,2,3)) fastener, the value is passed iterable

max () may be used in conjunction zip determine the size of the dictionary values

1, iterables max function processing is equivalent to a for loop that compares each element taken. Different types can not compare

2, a comparison between each element, sequentially compares the position of each element in a first, separated position if the first size. Do not need to compare the back of directly obtain the size of two elements

people=[
{'name':'alex','age':1000},
{'name':'wupei','age':10000},
{'name':'yuanhao','age':9000},
{'name':'linhaifeng','age':18},
]

print(max(people,key=lambda dic:dic['age'] ))

执行结果:{'name': 'wupei', 'age': 10000}

min()同上

oct()十进制转八进制

pow()  pring(pow(3,3,2))   3**3 %2

reversed()反转列表的顺序  ,区别与方法reverse,注意

re = [1,2,3,4] 
print(list(reversed(re)))

round()四舍五入
slice() s1 = slice(3,5)切片
sorted()临时排序,用法类似max()
c=_import_(test)导入模块,用在模块名是字符串类型的时候

Guess you like

Origin www.cnblogs.com/sxdpython/p/12640189.html