The Python built-in (built-in) function is created with the running of the python interpreter. In Python programs, you can call these functions at any time without defining them. The most common built-in functions are: The Python built-in (built-in) functions are created with the running of the python interpreter. In Python programs, you 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 Object map () filter () reduce ()
The following are all actual parameters. you can try the results directly on the command line.
Mathematical operations
Abs (-5) # obtain the absolute value, that is, 5
Round (2.6) # round the round, that is, 3.0
Pow (2, 3) # is equivalent to 2 ** 3. if it is pow (2, 3, 5), it is equivalent to 2 ** 3% 5
Cmp (2.3, 3.2) # compare the two numbers
Pmod () # returns the division result and remainder
Max ([,]) # calculate the maximum value
Min ([,-]) # calculate the minimum value
Sum ([2,-1, 9, 12]) # sum
Type conversion
Int ("5") # Convert to integer
Float (2) # Convert to float
Long ("23") # Convert to a long integer
Str (2.3) # Convert to string
Complex (3, 9) # returns the plural number 3 + 9i
Ord ("A") # The value corresponding to the "A" character
Chr (65) # character corresponding to the value 65
Unichr (65) # unicode character 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 = [, 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 True
Sorted ([, 3]) # returns the sequence in the forward order, that is, [, 5].
Reversed ([, 3]) # returns the reverse sequence, that is, [, 1].
Class, object, attribute
Python
1
2
3
4
5
6
7
8
9
# Define class
Class Me (object ):
Def test (self ):
Print "Hello! "
Def new_test ():
Print "New Hello! "
Me = Me ()
Hasattr (me, "test") # check whether the me object has the test attribute
Getattr (me, "test") # returns the test attribute.
Setattr (me, "test", new_test) # set the test attribute to new_test
Delattr (me, "test") # Delete the test attribute
Isinstance (me, Me) # whether the me object is an object generated by the Me class (an instance)
Issubclass (Me, object) # whether the Me class is a subclass of the object class
Compile and execute
Repr (me) # returns the string expression of the object
Compile ("print ('Hello')", 'Test. py', 'exec ') # compile the string to become a code object
Eval ("1 + 1") # interprets 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