Python-based built-in functions

Source: Internet
Author: User

Built-in Parameters
Print(All ([5,-1,5]))#not 0 is truePrint(All ([0,-1,5]))#falsePrint(Any ([1,0,5]))#One of the data is true, it's truePrint(Any ([]))#false#convert numbers to binaryPrint(Bin (1))" ">>> Bin (1) ' 0b1 ' >>> bin (2) ' 0b10 ' >>> bin (+) ' 0b10000 ' >>> bin (255) ' 0b11111111 ' >>>" "" "# True >>> bool (1) true>>> bool (0) false>>> bool (5) true>>> bool ([]) false> >> bool ({}) false>>> bool ({1}) true>>> bool ([241]) True" "" "A = bytes ("ABCD", encoding= "UTF8") print (A.capitalize (), a) b = ByteArray ("ABCD", encoding= "UTF8") print (b[1]) # Print asciib[1]= 50print (b)" "#Judging whether a thing can call true cannot call falsePrint(callable ([])) FalsedefABC1 ():PassPrint(Callable (ABC1)) True" "# ASCII numbers correspond to string conversions >>>>>>>>> chr ' a ' >>> chr (98) ' B ' >>> chr ' Z ' >>> chr ' C ' >>># in turn must enter ASCII characters converted into numbers >>> ord (' a ') 97>>> ord (' B ') 98>>> Ord (' C ') 99>>> ord (' 1 ') 49>>>" "" "# See what methods can be used >>> a = []>>>>>> dir (a) [' __add__ ', ' __class__ ', ' __contains__ ', ' __delattr__ ', ' __delitem__ ', ' __dir__, ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ', ' __getitem__, ' __gt__ ', ' __ Hash__ ', ' __iadd__ ', ' __imul__ ', ' __init__ ', ' __init_subclass__ ' ' __iter__ ', ' __le__ ', ' __len__ ', ' __lt__ ', ' __mul__ ', ' __ne__ ', ' __new__ ', ' __educe__ ', ' __reduce_ex__ ', ' __repr__ ', ' __reversed__ ', ' __rmul__ ', ' __setattr__, ' __setitem__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' append ', ' Clear ' copy ', ' Count ', ' extend ', ' index ', ' Insert ', ' Pop ', ' Remo ve ', ' Reverse ', ' sor ']>>>" "" "you can convert a string to the original data type, for example: The original is List, Dicteval ()" "" "The # exec function is primarily used to execute statement blocks >>> exec (' a=1+3*2*2 ') >>> exec<built-in function exec>>>> A13 >>>" "

defABC1 (n):Print(N) ABC1 (3)#Pass Parameters(LambdaC:Print(c)) (110) ABC=LambdaC:Print(c) ABC (5) ABC=LambdaC:10ifC<5ElseCPrint(ABC (3))Print("===========================================")#Filter#Print the >6res = filter (LambdaN:n>6,range (10)) forIinchRes:Print(i)Print("===========================================")#Map#Take each of the data out of the collection to the previous function and print it in list mode .res = map (LambdaN:n*2,range (10)) forIinchRes:Print(i) 024681012141618Print("===========================================")#Cumulative ReduceImportFunctoolsres= Functools.reduce (LambdaX,y:x+y,range (1,10))Print(RES)#Tired Rideres = Functools.reduce (LambdaX,y:x*y,range (1,10))Print(RES)Print("===========================================")#determine if the variable exists no#Print (Globals ())" ">>>>>> Hash (1) 1>>> hash (2) 2>>> hash ("Ming") 2265504022069637367>> >>>> Hash ("Mike") -5868197253725756830>>>" "#convert a number to 16 binary" ">>>>>> Hash (1) 1>>> hash (2) 2>>> hash ("Ming") 2265504022069637367>> >>>> Hash ("Mike") -5868197253725756830>>>" "#returns the number of times a power, such as the Y-square of a POW (x, y) x" ">>>>>> Pow (3,3) 27>>> pow (5,2) 25>>> pow (8,2) 64>>>" "#sort from small to largeA = {6:2,8:0,1:4,-5:6,99:11,4:22}#print (a)Print(Sorted (a)) [-5, 1, 4, 6, 8, 99]Print(Sorted (A.items ()))#Key Sort[(-5, 6), (1, 4), (4, 22), (6, 2), (8, 0), (99, 11))]Print(Sorted (A.items (), key=LambdaX:X[1]))#Sort by value, X represents an element[(8, 0), (6, 2), (1, 4), (-5, 6), (99, 11), (4, 22))]Print("===========================================")#match two lists and merge them into oneD= [1,2,3,4,5,6]e= ['a','b','C','D','e','F'] forIinchZip (d,e):Print(i) (1,'a')(2,'b')(3,'C')(4,'D')(5,'e')(6,'F')Print("===========================================")__import__('Generator')

Python-based built-in functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.