__author__ = ' Coco ' ' python built-in function ' ' # All () is true for true print (all ([0,-2,3]) # Falseprint (All ([1,-2,3]) # true# any () is true, then For true print (any ([1,-6,3]) # Trueprint (Any ([0, ', 1]) # true# bin () decimal to binary print (Bin (8)) #0b1000 # bool () to determine the true and false print (bool (0)) # Falseprint (bool ( -1)) # true# bytes () string into binary byte form, non-modifiable a = bytes ("ABCDE", encoding= "Utf-8") print (A.capitalize (), a) # ByteArray () change binary string b = ByteArray ("ABCDE", encoding= "Utf-8") print (b[1]) B[1]=50print (b) #callable () Determine if Def sayhi () can be called: Passprint (Callable (Sayhi)) # true# Chr () returns the ASCII counterpart table print (CHR) # a# Ord () ASCII return digital print (ORD (' d ')) # 100# compile () bottom The # exec () used to compile the code can execute code directly, even if it has been assigned to the string code= "for I in Range": Print (i) "EXEC (code) # delattr (object,name) # Delete Obje CT object named Name property # dict () Generate Default Dictionary # DIR () Query method Print (dir (Dict ())) # Enumerate () to list build index # eval () run python expression x = 1print (eval (' x+1 ' ) # # anonymous Function calc = lambda n:print (n) Print (Calc (5)) # can also be ternary operation CALC2 = Lambda N:3 if n<4 else Nprint (CALC2 (5)) # filter () filtering res = filter (lambda n:n>5,range) for I in Res:print (i) #map () One is a function, and the other is that Iterable,map functions the incoming function sequentially to each element of the sequence and returns the result as a new iterator. res = map (lambda n:n*n,range) for I in Res:print (i) #==>[Lambda i:i*2 for me in Range (Ten)] #reduce () python2.x is re Duce,python3.x moved to Functools. Reduce puts a function in a sequence [X1, x2, x3, ...] , this function must receive two parameters, reduce to continue the result and the next element of the sequence to do a cumulative calculation import functoolsres = Functools.reduce (lambda x,y:x+y,range) print (res) # 45# Frozenset So it becomes immutable a = Frozenset (set ([1,2,4,5,6,4])) #globals () returns the program variable dictionary #hash () hash, hash (mapping Relationship) #help () help #hex () Convert a number to 16 binary print (Hex (255)) # ' 0xFF ' # locales () print local variable #next () remove a value #oct () to 8 binary print (Oct (8)) #pow () returns how many power print (POW (2,5) ) #reversed () Invert # round () print (round (1.31678,2)) # sorted () Sort # Sort the dictionary--list #sorted (A.items ()) #按key #sorted (A.items () , Lambda X:x[1]) #按value #zip () fused a = [1,2,3,4]b = [' A ', ' B ', ' C ', ' d ']for i in Zip (A, B): print (i) # import ' Decorato R ' # __import__ (' decorator ')
Common built-in methods for Python