Python's commonly used built-in functions

Source: Internet
Author: User

Python built-in functions, which can be build-in Functions via Python's help document, can be viewed via commands under terminal interaction
>>> dir ("__builtins__") [' __add__ ', ' __class__ ', ' __contains__ ', ' __delattr__ ', ' __dir__ ', ' __doc__ ', ', _eq__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ', ' __getitem__ ', ' __getnewarg,__ ', ' __gt__ ', ' __hash__ ', ' __init__ ', ' __ iter__ ', ' __le__ ', ' __len__ ', ' __lt__, ' __mod__ ', ' __mul__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __epr_ ' _ ', ' __rmod__ ', ' __rmul__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __subcasshook__ ', ' capitalize ', ' Casefold ', ' Center ', ' Count ', ' encode ', ' endswith ', expandtabs ', ' find ', ' format ', ' format_map ', ' index ', ' isalnum ', ' isalpha ', ' Isecimal ', ' isdigit ', ' isidentifier ', ' islower ', ' isnumeric ', ' isprintable ', ' issace ', ' istitle ', ' isupper ', ' join ', ' Ljust ', ' Lower ', ' Lstrip ', ' Maketrans ', ' prtition ', ' replace ', ' rfind ', ' rindex ', ' rjust ', ' rpartition ', ' rsplit ', ' Rstri ' ', ' Split ', ' splitlines ', ' startswith ', ' strip ', ' swapcase ', ' title ', ' Translat ', ' Upper ', ' Zfill ']
Python built-in functions can be divided into roughly several categories

Numeric operations

ABS ( -1) #取绝对值或者复数的模max ([5,2]), min ([[+]) #最大最小值len (' ABC '), len ([2,1]), len ((+)) #序列长度divmod (+/-) Built-in function to put ... Converted into a complex number, such as complex (' 2 ') return (2+0j), complex (' 2+3j ') returns (2+3j) POW () # built-in function, Exponentiation. If there is a third argument, the result of the exponentiation is the remainder of the third parameter, such as W (2,3) return 8,pow (2,3,4) returns the 0round (1)//1.0# floating-point number

Functional judgment

The callable ("variable") #函数是否可调用. Note: variables to be defined over isinstance (x,[11,22,33]) #判断X是不是有列表或者整型等, if yes, return true, not return falsecmp (' Hello ', ' Hello ') #比较 (x) range ([start,] stop[, step]) # Fast sequence generation

Type conversions

Long (x) float (x) #把: Convert to floating point complex (x)//plural str (x) #转换成字符串list (x) #转换成字符串tuple (x)//tuple-in-the-workpiece Conversion r = Hex (ten) #十六进制 r = Oct #八进制 r= bin (ten) #二进制 r= i NT (65) #十进制 i= int ("one", base=10) #进制间的相互转换base后跟 2/8/10/16 print (i) chr (x)//return x for the corresponding character, such as CHR (A.) return ' A ' ord (x)// Returns the ASC code number corresponding to the character, such as Ord (' A ') return 65# The most common example is the birth random verification code Import RANDOMTEMP = "" for i in range (4):    num = Random.randrange (0,4)    if num = = 3 or num = = 1:        li = random.randrange (0,10)        temp = temp + str (li)    else:        rad = Random.randran GE (65,91)        c = chr (rad)        temp + = Cprint (temp)

Sequence processing

Len (): sequence length max (): maximum min () in sequence: min. reduce (): merge filter (): filter sequence, Use the following def F1 (x):    # if x >:    #     return True    # else:    #     return False    return x >22# ret = Filter (f1,[11,22,33,44]) ret = filter (lambda x:x > 22, [ 11,22,33,44]) for i in ret:    print (i) map (): parallel traversal, can accept parameters of a function type, with the filter () function zip (): parallel traversal, usage specific as follows F1 = ["a", "b", "c"] F2 = [11,22,33]set = Zip (f1,f2) for i in set:    print (i)

Type () returns a data type, and so on

 

 

  

  

  

Python's commonly used 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.