Python Learning-built-in functions

Source: Internet
Author: User
Tags pow

Built-in methods:
1:abs (): Take absolute value
2:all (): The result is true when all the objects in the iterator are true. All ([+])
3:any (): True if any of the data in an iterative object is a true result. Any ([0,1,2])
4:ascii (): Prints an object as a string representation. [ASCII ([1, ' Hello '])] low utilization.
5:bin (x): Turns decimal integers into binary. Bin (1)/bin (255) starts with 0b.
6:bool (): True and false judgment
7:bytearray (): Can be modified in binary byte format. Rarely used
b = ByteArray (' abcde ', encoding= ' utf-8 ')
B[0] = 50
Print (b)
After converting to a list, the corresponding characters can be modified by giving the ASCII corresponding data.
8:bytes (): Conversion to binary format
9:callable (): Determines whether it can be called, (function, Class)
10:CHR (): Returns the ASCII character corresponding to the number. Chr (98)
11:ord (): Returns the number of the ASCII table that corresponds to the character.
12:compile (): Perform the underlying compilation of the code. Seldom useful. Can be replaced directly with EXEC ().
13:complex: plural.
14:dir: View method (Help). Dir (dict)
15:divmod (): Returns the quotient and remainder in tuple form. Divmod (5,2) value is: (2,1)
16:enumerate (): Returns the element and index values of the Iteration object.
17:eval (): evaluates the string str as a valid expression and returns the result of the calculation.
18:exec (): Dynamically executes Python code. This means that exec can execute complex python code, unlike the Eval function, which only evaluates to the value of an expression.
The eval () function differs from the EXEC () function:
The eval () function evaluates only the values of a single expression, and the Exec () function can run code snippets on the fly.
The eval () function can have a return value, and the EXEC () function return value is always none.
19:filter (): Filters and prints only the data that meets the criteria.
res = filter (lambda n:n>5,range (10))
For I in Res:print (i)
20:map (): Pass the list data in sequence to the function to execute and print
res = map (lambda n:n*n,range) #相当于列表生成式
For I in Res:print (i)
Python3 reduce to Functools, use the following:
Import Functools
res = Functools.reduce (lambda x,y:x+y,range (10))
Print (RES)
Function: Implement list accumulation
21:float (): floating-point type
22:format (): String formatting
23:frozenset (): Immutable collection.
A = Frozenset ([1,2,3,4,5,6])
24:globals (): Returns all variables (global variables) in the current program in the form of a dictionary. Print (Globals ())
25:hash (): Unique value corresponding to the data. Hash (' Test ')
26:help (): View Help
27:hex (x): Converts the number to 16 binary. Hex (255)
28:id: Return memory address
29:input: Interactive
30:int: Integer
31:isinstance (): Determines whether an object can be iterated.
32:iter (): iterator
33:len (): Print sequence length
34:locals (): Print only local variables
35:max: Returns the maximum value
36:min: Returns the minimum value
37:next: Ring as Next in the iterator
38:OCT (): Turn 8 binary. Oct (8)/oct (9),
39:open (): Hit file
40:pow (X,y[z]): Power party. POW (2,3) returns 2 of the 3-time Square
41:range (): Generates a list of 0 to a specified number in an iterative form.
42:repr (): Represents an object as a string. Less useful
43:reversed (): Reverse sort
44:round (): retains the specified number of digits. Round (1.223,2) value: 1.22 The specified number of digits after the decimal point is reserved.
45:set (): Collection
46:slice: Slice. Forget him.
47:sorted (): Sorts the sequence.
To sort a dictionary:
D1 = {...}
Print (sorted (A.items ()) enables dictionary key ordering
Print (sorted (A.items (), Key=lambda x:x[1]) to sort the values of the dictionary
48:STR: String
49:sum (): Sum
50:tuple (): Tuples
51:type (): View data type
52:vars (): Returns all property names for the object. Less useful.
53:zip (): Combines the number of 2 list corresponding indexes by the minimum number.
A = [1,2,3,4], b = [' A ', ' B ', ' C ', ' d ', ' e ', ' F ']
For I in Zip (A, B): print (i)
54:__import__ (' string '): Import functions as strings

Python Learning-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.