Python built-in functions are created as the python interpreter runs. In a Python program, 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 types type()
Look back 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 parameters are all actual parameters. You can try the effect directly on the command line.
Mathematical operations
abs(-5) because , 3) # is equivalent to 2**3, if is pow(2, 3, 5), which is equivalent to 2**3 % 5
cmp(2.3, 3.2) max ([1,5,2,9]) Sum
type conversion
int(“5″)
long(“23″) str(2.3) # The numerical value corresponding to the “A” character chr(65) The character corresponding to 65 unichr(65) In Python, the following objects They are equivalent to false: [], (), {}, 0, none, 0.0, "Bin (56)# Return a string, indicating that 56 binary numbers Hex (56)# Return a character back to a character String, representing the hexadecimal number of 56oct(56)tuple( [2,3,4])
slice(5,2,-1) # Construct the subscript object slice
dict(a=1,b="hello", c=[1,2,3])
all([True, 1, "hello!"]) # Whether all elements are equivalent to the True value
any(["", 0, False, [], None]) # Whether any element is equivalent Based on the True value
sorted([1,5,3]) The sequence of order, that is, [3,5,1]
class, object, attribute
Python
1
2
3
" ello!"
def new_test():
Print "New Hello!"
me = Me()
hasattr(me, "test") # Check whether the me object has the test attribute
getattr (me, "test") # Whether the me object is an object generated by the Me class (an instance)
issubclass(Me, object) Express iCompile ("Print ('Hello')", 'Test.py', 'EXEC')# compile string becomes CODE objects
eval ("1 + 1 ″)# Explanation string expression. 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:")
locals()