1. Built-in functions
1 Print(All ([1,2,3,0]))#determine if the objects inside an iterative object are true: Non-zero-true non-null-true principle2 Print(Any ([1,2,3,0]))#determine if there is a true in an iterative object: Nonzero is true non-null is true principle3 Print(Bin (100))#Decimal Turn binary4 Print(Chr (65))#print the ASCII corresponding to the number5 Print(Ord ('A'))#Print the ASCII corresponding number6 Print(Dir ('A'))#Print all the methods that the passed object can invoke7 Print(Eval ("{' A ': 2, ' B ': 3}"))#execute Python code, simply execute, define data types and operations (words have an evaluation meaning) #可以将字符串转换为字典, arrays, Ganso #https://www.cnblogs.com/liu-shuai/p/6098246.html 8 Print(exec("'))#execute Python code, simply execute, define data types and operations9A = 1Ten exec('A = a+1') One Print(a)#Output: 2 A #zip () loops two list at the same time, or more than one list, when the list number does not match, the number is whichever is less -ids = [+/-] -names = ['Xiaohei','Xiaobai','Xiaohuang'] the forI,ninchZip (ids,names): - Print(i,n) - - #Sorted Ascending order +ids = [1,2,3,-3] - Print(Sorted (IDS))#Ascending order + Print(Sorted (ids,reverse=true))#Descending arrangement A Print(Round (4.3333,2))#keep several decimals, if rounded, the last one is 0, does not show
2. Map and filter loop call function
The map loop invokes the function, placing the result of each function processing in the map, returning the Map object, which can be cast to List view, simplifying the code
def func (a): if a%2 = = 0: return a else: return falsenum = [x for x in range]]res = map (func,num) print ( RES) #<map object at 0x0000000000c5aa90>print (list (res)) #[0, False, 2, False, 4, False, 6, false, 8, false, 10]
The filter loop invokes the function, returning only the result to true, which can be cast to List view, simplifying the code
1 deffunc (a):2 ifa%2 = =0:3 returna4 Else:5 returnFalse6num = [x forXinchRange (11)]7res =filter (Func,num)8 Print(List (res))#[2, 4, 6, 8, ten]
"Python" Learning note 4-built-in functions