Author: vamei Source: http://www.cnblogs.com/vamei welcome reprint, please also keep this statement.
The Python built-in (built-in) function is created with the running of the python interpreter. In pythonProgramYou can call these functions at any time without defining them. The most common built-in functions are:
Print ("Hello world! ")
In the python tutorial, we have mentioned the following built-in functions:
Basic data type ()
Look at Dir () Help () Len ()
Dictionary Len ()
Text File Input and Output open ()
Loop Design range () enumerate () Zip ()
Loop object ITER ()
Function objectMap ()Filter () Reduce ()
The following are all actual parameters. You can try the results directly on the command line.
Mathematical operations
ABS (-5)# Take the absolute value, that is, 5
Round (2.6)# Rounding to an integer, that is, 3.0
Pow (2, 3)# Equivalent to 2 ** 3. For POW (2, 3, 5), equivalent to 2 ** 3% 5
CMP (2.3, 3.2)# Compare the size of two numbers
Divmod (9, 2)# Return the division result and remainder
Max ([1, 5, 2, 9])# Maximum value
Min ([9, 2,-4, 2])# Minimum value
Sum ([2,-1, 9, 12])# Sum
Type conversion
INT ("5 ")# Convert to integer
Float (2)# Converting to float
Long ("23 ")# Convert to a long integer
STR (0, 2.3)# Convert to string
Complex (3, 9)# Return the plural 3 + 9i
Ord ("")# Value corresponding to the "A" Character
CHR (65)# Characters corresponding to the value 65
Unichr (65)# Unicode characters corresponding to the value 65
Bool (0)# Convert to the corresponding real 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 that represents the number of BITs 56.
Hex (56)# Returns a string representing the hexadecimal number of 56.
Oct (56)# Returns a string that represents the number of octal digits of 56.
List (1, 2, 3 ))# Convert to table list
Tuple ([2, 3, 4])# Convert to a value table tuple
Slice (5, 2,-1)# Construct the subscript object slice
Dict (a = 1, B = "hello", c = [1, 2, 3])# Build a dictionary
Sequential operation
All ([true, 1, "Hello! "])# Whether all elements are equivalent to true
Any (["", 0, false, [], none])# Whether any element is equal to the value of true
Sorted ([1, 5, 3])# Return the forward sequence, that is, [1, 3, 5].
Reversed ([1, 5, 3])# Return the reverse sequence, that is, [3, 5, 1]
Class, object, attribute
# Define class
ClassMe (object ):DefTest (Self ):Print "Hello!"
DefNew_test ():
Print "New hello! "
Me= Me ()
Hasattr (Me, "test ")# Check whether the me object has the test attribute
Getattr (Me, "test ")# Return test attributes
Setattr (Me, "test", new_test)# Set the test attribute to new_test
Delattr (Me, "test ")# Deleting the test attribute
Isinstance (Me, me)# Whether the me object is an object generated by the me class (an instance)
Issubclass (Me, object)# Is the me class a subclass of the object class?
Compile and execute
Repr (me)# String expression of the returned object
Compile ("Print ('hello')", 'test. py', 'exec ')# Compile a string to become a code object
Eval ("1 + 1 ")# Interpret string expressions. The parameter can also be the code object returned by compile ().
Exec ("Print ('hello ')")# Interpret and execute the string, print ('hello ').The parameter can also be the code object returned by compile ().
Others
Input ("Please input :")# Waiting for Input
Globals ()# Return the global namespace, such as the global variable name and global function name.
locals () # return a local namespace