1. High-frequency knowledge points:
string
upper(): lowercase becomes uppercase
lower(): uppercase becomes lowercase
strip(): spaces before and after the string are omitted
count(): counts a character in the string
len(): length of the string
split( ): Segment the string
join():
startswith(): judge whether it starts with a certain character
endswith(): judge whether it ends with a certain character
isdigit(): judge whether it is an integer type string
isalpha(): Determine whether it is an all-English string
the list
append(): Insert at the end of the list
len(): the number of elements in the list, the length of the list
count(): count the number of elements in the list insert(): insert pop(
in a list according to the subscript index
): Delete an element at a certain position in the list according to the subscript
index index(): Index an element
dictionary
del: delete a key-value pair
keys(): return all keys
values(): return all values
pop(): delete a key-value pair according to the key
get(): query a key-value pair according to the key
len( ): the number of key-value pairs in the dictionary
integer
floating point number
Boolean value
2. Text file reading and writing
read-write mode
r: read only, error will be reported if there is no file
w: write only: no file will be created, overwrite
a: append write, no file will be created, append write
r+: readable and writable, error will be reported if there is no file
w+: readable and writable, no Will create, overwrite
a+: readable and writable, will not create, append write
open a file
The file opened by open() needs to be closed manually, that is, it must be closed with close().
Files opened with open need to be closed manually.
key function
read(): The return value is a string, read at one time
readline(): The return value is a string, read line by line
readlines(): The return value is a list, read at one time, but there is a space at the end of the element
read-write mode | write() |
---|---|
r+ | Overwrite at the beginning |
w/w+ | full overwrite |
a/a+ | Append write |
3. Regular expressions
function | describe | match description |
---|---|---|
re.match() | Match the specified pattern at the beginning of the string | match for the first time |
re.search() | Match the specified pattern anywhere in the string | match for the first time |
re.findall() | Match the specified pattern anywhere in the string | match all keywords |
re.sub() | Specifies the string to replace with the matched string |