Python Quick Tutorials (supplement): Python built-in function list

Source: Internet
Author: User
Tags pow

The Python built-in (built-in) function is created as the Python interpreter runs. In Python programs, you can call these functions at any time, and you don't need to define them. The most common built-in functions are:

Print ("Hello world!")

In the Python tutorial, we have mentioned some of the following built-in functions:

Basic datatype type ()

Look back at Dir () help () Len ()

Dictionary Len ()

Input and output of text file open ()

Loop design Range () enumerate () Zip ()

Cyclic object iter ()

function Object Map () filter () reduce ()

The following are all the actual parameters, and you can try the effect directly on the command line.

Mathematical operations

ABS (-5) # take absolute value, i.e. 5

Round (2.6) # rounded rounding, which is 3.0

Pow (2, 3) # equivalent to 2**3, if it is POW (2, 3, 5), equivalent to 2**3% 5

CMP (2.3, 3.2) # Compare the size of two numbers

Divmod (9,2) # returns the division result and remainder

Max ([1,5,2,9]) # Ask for maximum value

MIN ([9,2,-4,2]) # to find the minimum value

SUM ([2,-1,9,12]) # sum

Type conversions

Int ("5″") # is converted to an integral integer

Float (2) # Convert to floating-point float

Long ("23″") # converted to long integer long integers

STR (2.3) # converts to string strings

Complex (3, 9) # returns complex number 3 + 9i

Ord ("A") # "a" character corresponding value

Chr (65) # Number 65 corresponds to the character

UNICHR (65) # VALUE 65 corresponds to the Unicode character

BOOL (0) # converted to the corresponding true and False value, in Python, 0 is equivalent to False

In Python, the following objects are equivalent to false: [], (), {}, 0, None, 0.0, "

Bin (56) # Returns a String representing a binary number of 56

Hex (56) # Returns a String that represents the hexadecimal number of 56

Oct (56) # Returns a String that represents the octal number of 56

List (()) # Convert to Table list

Tuple ([2,3,4]) # Convert to fixed value table tuple

Slice (5,2,-1) # Build Subscript Object Slice

Dict (a=1,b= "Hello", c=[1,2,3]) # Build Dictionary Dictionary

Sequence operations

All ([True, 1, "hello!"]) # If all elements are equal to true values

Any (["", 0, False, [], None]) # is there any one element equal to the true value

Sorted ([1,5,3]) # Returns the sequence of the positive sequence, i.e. [1,3,5]

Reversed ([1,5,3]) # Returns the sequence of the reverse order, i.e. [3,5,1]

Class, Object, property

Python
123456789 # define Classclass Me(object): def Test(self): print "hello!" def new_test(): print "New hello!" me = me()

Hasattr (Me, "Test") # Check if the Me object has a test property

GetAttr (Me, "test") # Returns the Test property

SetAttr (Me, "test", New_test) # Set the test property to New_test

Delattr (Me, "test") # Delete test property

Isinstance (Me, Me) # Me object is the object generated by the Me class (a instance)

Issubclass (Me, Object) # Me class is a subclass of the object class

Compile, execute

Repr (Me) # Returns the string representation of an object

Compile ("Print (' Hello ')", ' test.py ', ' exec ') # Compile string becomes code object

Eval ("1 + 1″) # explains the string expression. The parameter can also be a code object returned by the compile ()

EXEC ("Print (' Hello ')") # interprets and executes the string, print (' Hello '). The parameter can also be a code object returned by the compile ()

Other

Input ("Please input:") # Wait for input

Globals () # Returns the global namespace, such as global variable name, global function name

Locals () # returns the local namespace

All-in-one programmer Exchange QQ Group 290551701, gather a lot of Internet elite, technical director, architect, Project Manager! Open source technology research, Welcome to the industry, Daniel and beginners are interested in engaging in IT industry personnel to enter!

Python Quick Tutorials (supplement): Python built-in function list

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.