1. Scope-related
Function: returns the name in the scope.
Function: returns the name in the global scope.
2. Related to the iterator/Generator
Function: generate data
lst = [i for i in range(10)]print(lst) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Function: gets the iterator. The _ ITER _ () method is used internally to obtain the iterator.
Function: The iterator is executed once. The _ next _ () method is used internally to return to the next project of the iterator.
LST = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ret = ITER (LST) # Get iterator print (next (RET )) #0 execute iterator
3. Execution of string-type code
Function: Run string-type code. And return the final result.
print(eval("[11, 22, 33, 44]")) # [11, 22, 33, 44]print(eval("2+2")) # 4def func(): print(666)eval("func()") # 666
Function: executes string-type code.
Exec ("" For I in range (10): Print (I )""") #0 1 2 3 4 5 6 7 8 9 exec ("def func (): Print (" I am selia ") func ()""") # I'm Silea
Function: Compile the code of the string type. The code in the form of a string with a return value is evaluated using eval (). The code in the form of a string without a return value is executed using exec ().
Parameter description:
1) Resource: code to be executed, dynamic code snippets
2) file name: the name of the file stored in the Code. When the first parameter is input, this parameter can be left blank.
3) mode, with three values:
A) Exec: when some process statements are put
B) Eval: resource only stores one evaluate expression.
C) Single: when the resource stored code interacts with each other, the mode should be single, but only one line of the Code is allowed. Otherwise, an error is returned.
Code = "For I in range (5): Print (I)" "C1 = compile (Code," ", mode =" EXEC ") exec (C1) #0 1 2 3 4code2 = "name = input (" enter your name: ")" "C2 = compile (code2 ,"", mode = "single") exec (C2) print (name) # Tom
4. Input and Output
Function: Get user input
Function: print the output.
5. Memory-related
Function: obtains the hash value (INT, bool, STR, tuple) of an object)
Note:
1) the hash value of a number is itself
2) the hash value obtained by calling Hash () is different (except for numbers), so the hash value cannot be used as a password.
Num = 10 s = "hello" Print (Hash (Num) #10 # print (Hash (s) for the first call #3718209680369926059 # print (Hash (s) for the second call )) #263127024043316082
Function: gets the object's memory address.
6. File-related
Function: used to open a file and create a file handle.
7. Module-related
Function: Used to dynamically load classes and functions
8. Help
Function: view detailed descriptions of functions or modules.
9. Call related
Function: checks whether an object is callable. If true is returned, the object may fail to be called, but if false is returned, the call will never succeed.
n = 10def func(): passprint(callable(n)) # Falseprint(callable(func)) # True
10. View built-in attributes
Function: view the built-in attributes and methods of an object. The _ DIR _ () method of the object is accessed.
11. Basic Data Types 1) and numbers a) Data Types
Function: converts a given data to a bool value. If no value is specified, false is returned.
Function: converts a given data to an int value. If no value is given, 0 is returned.
Function: converts a given data to a float value, that is, a decimal number.
Function: create a complex number. The first parameter is the real part, the second parameter is the virtual part, or the first parameter is used to describe the complex number directly.
B) hexadecimal conversion
Function: converts a parameter to a binary value.
Function: converts a parameter to an octal value.
Function: converts a parameter to a hexadecimal value.
C) mathematical operations
Function: returns the absolute value.
Function: Return operator and remainder
Function: Rounding
For X.5, if the number of digits of an integer is an even number near the even number, the number of digits of an integer is discarded if the number of digits of an integer is an odd number near the even number.
print(round(4.5)) # 4print(round(5.5)) # 6print(round(5.4)) # 5
Function: Calculate the power of B of A. If there are three parameters, the remainder of the third number is obtained after the power is obtained.
print(pow(2, 3)) # 8print(pow(2, 3, 5)) # 3
Function: Sum
Function: Minimum value
Function: calculates the maximum value.
2) A) List and metadata related to the Data Structure
Function: converts an iteratable object to a list.
Function: converts an iteratable object to a metagroup.
Function: returns the iterator of the flip sequence.
lst = [1, 2, 3, 4, 5, 6]ret = reversed(lst)print(ret) # <list_reverseiterator object at 0x000001B589038208>for i in ret: print(i) # 6 5 4 3 2 1
Function: slice of the List
lst = [1, 2, 3, 4, 5, 6]s = slice(1, 5, 2)print(lst[s]) # [2, 4]
B) string-related
Function: converts data into strings.
Function: related to specific data, used to calculate various decimals, actuarial, etc.
# String print (format ('test', '<20') # Left-aligned print (format ('test','> 20 ')) # Right-aligned print (format ('test', '^ 20') # center # value print (format (3,' B '))#? Hexadecimal print (format (97, 'C') # convert to the Unicode Character print (format (11, 'D '))#? Hexadecimal print (format (11, 'O '))#? Hexadecimal print (format (11, 'x '))#? Hexadecimal (? Write letters) print (format (11, 'x '))#? Hexadecimal (? Write letters) print (format (11, 'n') # print (format (11) like D # Same as D # print (format (123456789, 'E') # scientific notation. print (format (123456789, '0. 2e') # scientific notation. retain 2 decimal places (lower case) print (format (123456789, '0. 2e') # scientific notation. retain 2 decimal places (uppercase) print (format (1.23456789, 'F') # decimal point count. retain 6 decimal places print (format (1.23456789, '0. 2f ') # number of decimal points. retain 2 decimal places print (format (1.23456789, '0. 10f') # number of decimal points. print (format (1.23456789e + 10000, 'F') with 10 decimal places.
Function: converts a string to a bytes type.
S = "hello" BS = bytes (S, encoding = "UTF-8") print (BS) # B '\ xe4 \ xbd \ xa0 \ xe5 \ xa5 \ xbd'
Function: returns a new byte array. The elements in this array are variable and the value range of each element is [0,256].
ret = bytearray(‘alex‘, encoding=‘utf-8‘)print(ret) # bytearray(b‘alex‘)ret[0] = 65print(ret) # bytearray(b‘Alex‘)
Function: view the memory usage of bytes.
S = "hello" ret = memoryview (S. encode ("UTF-8") print (RET) # <memory at 0x0000022fc0071048>
Function: Enter characters to find the location with character encoding
Function: enter a number to find the corresponding character
Function: return this value in the ASCII code. If the value is not in the ASCII code, \ U... is returned...
S = "hello" Print (ASCII (s) # '\ u4f60 \ u597d'
Function: returns the official representation of an object.
S = "Hello \ My Name Is cyliya" Print (Repr (s) # 'Hello \ My Name Is cyliya 'print (s) # Hello \ My Name Is cyliya
C) Data Set
Function: Creates a dictionary.
Function: Creates a set.
Function: Creates a frozen set. Frozen sets cannot be added or deleted.
D) other related
Function: returns the number of elements in an object.
Function: sorts iteratable objects.
- Enumerate (iteratable object, start = 0)
Function: obtains enumeration objects of a set.
LST = [11, 22, 33] For index, El in enumerate (LST): Print (index, El) Result: 0 111 222 33
Function: all objects that can be iterated are true, and the result is true.
print(all([1, 2, 0, True])) # False
Function: if one of the iteratable objects is true, the result is true.
print(any([1, 2, 0, True])) # True
Function: a function is used to package the corresponding elements of an object into tuples and return a zip object consisting of these tuples. If the elements of each iterator are inconsistent, the returned object length is the same as that of the shortest object.
lst1 = [1, 2, 3]lst2 = ["a", "b", "c", "d"]lst3 = (11, 22, 33, 44, 55)print(zip(lst1, lst2, lst3)) # <zip object at 0x000001E7D275BF48>print(list(zip(lst1, lst2, lst3))) #[(1, ‘a‘, 11), (2, ‘b‘, 22), (3, ‘c‘, 33)]for i in zip(lst1, lst2, lst3): print(i) # (1, ‘a‘, 11) (2, ‘b‘, 22) (3, ‘c‘, 33)
The built-in function structure is as follows:
Https://www.processon.com/mindmap/5bdbfba6e4b0e452133837a3
Built-in functions