python-built-in function summary

Source: Internet
Author: User
Tags first string

The built-in function, the Python builtin function (build in function), does not need to refer to other packages, generally becomes BIF ABS () calculates the absolute value, ABS (-10), receives number, returns the maximum (iterative) of the sequence for the Count Max () Also can compare some number min () to find the minimum value of the sequence (iterative), but also can compare some number Len () to find the length of the sequence, (the dictionary can also, the number of index) Divmod (x, y) to find the quotient and remainder of x, y, stored in the tuple of POW (x, y, z)    Y-square, if there is a third parameter, then the previous result and the third parameter of the remainder round (number) is used to 40 percent five in, followed by the accuracy (number of the number programming floating-point number, and then see the retention of several) examples: Convert 12.45 to float, then it's not 12.45, and it's probably 12.4999999. Callable () determines whether an object is callable, such as a function, the class is callable, but the variable cannot call type () to see the object's types Isinstance (object, type) determines whether an object is of the given type. Type can be multiple, as long as there are 1 of them (type 1, type 2)
A='213'isinstance (a,str) returns True
CMP (x, y) compares the size of two objects, X is greater than y returns 1,x equals y returns -1,x less than Y returns-1, strings can also be compared, which is the size of a single character to begin with. STR () can convert any data into a string (dictionary, tuple, also direct output) Hex (10) converts 10 binary to 8 eval () evaluates the string as a valid expression
Eval ('1+2') returns 3eval ("[[+]]")
The OCT () converts the 10 binary into a 8-input Chr (i) I is 0~255, the range of the Acsii code value of ord (i) I is the ASCII value, the corresponding value string processing related function (method) A.capitalize () to the string A to capitalize the first letter, The first letter is the number is unchanged A.replace (Old,new,[count]) replace the old string with the new string, count can go to specify the replacement several times a.split (delimiter, [Cut several]) to separate the string, return a list, The default is a space or tab-delimited (there are several spaces that do not matter, all as 1) separators. Join (an Iterative object) returns a string that iterates over an iterative object into a string, separates the string module with a delimiter, and imports a string module (import String) string.lowercasestring.uppercase print all uppercase and lowercase letters string.capitalize (' hello ') to replace the first string with the upper case string.replce (' Hello '), ' L ', ' a '), replace the L in Hello with a filter (function or empty, sequence) to filter, and give each element of the sequence to the function to process. If none, then do nothing, direct output (sequence), if there is a function, then only the return value of the function is true to print the sequence of elements in the example:
def even (n): if n% 2 = = 0:  return  truefilter (Even,xrange (2, 4, 6, 8)
Advanced wording:
Filter (lambda x:x%2 ==0,xrange (10)

Zip (seq1,seq2,seqn ...) Combining SEQ1 and SEQ2 into 1 large lists, each sequence takes 1 constituent tuples, which are stored in the Consolidated list, and if the length of the sequence is different, the length of the smallest sequence is the basis. Map (FUNC,SEQ1,SEQ2) Return is also a list, Func can be a function or none, if none, then the returned list length is the current longest list as the benchmark, still is to go to each list in order to fetch, but no, with none to add an example:
L1 = [1, 2, 3]l2= ['a','b','C','D']l3= ['I','II','III','IV','V','VI']map (NONE,L1,L2,L3) [(1,'a','I'),(2,'b','II'),(3,'C','III'), (None,'D','IV'), (none, none,'V'), (none, none,'VI')]
If the function bit is a function, then if there is only 1 list, then you need the function to define 1 parameters, and then each time the list of 1 elements to the function for processing, and printing if you need to process two series, then the function must define 2 parameters to accept the elements of the two sequences. Advanced Applications:
Map (Lambda x,y:x+y,l1,l4)

Reduce (FUNC,SEQ) can only define 1 sequences, which are then passed to Func for processing. (lambda function Additive)

python-built-in function summary

Related Article

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.