python split() strip() method

Recently, I often encountered this function when learning deep learning data reading. Check the relevant knowledge records as follows.

str.split(str="", num=string.count(str)).

Parameters:
str-separator, default is all empty characters, including space, newline (\n), tab (\t), etc.
num-the number of divisions. The default is -1, which means that all are separated.
Return value:
Python split() slices the string by specifying the separator. If the parameter num has a specified value, it separates num+1 substrings and returns the split string list.

A="www qqq eee qqq"
B=A.split()
print(B)

Insert picture description here

A="www qqq eee qqq"
B=A.split()[0]
print(B)

Insert picture description here
str.strip([chars]), the parameter chars-remove the specified characters at the beginning and end of the string. Used to remove the specified characters at the beginning and end of the string (the default is a space)

A="www qqq eee www"
B=A.strip("w")
print(B)

Insert picture description here

Guess you like

Origin blog.csdn.net/ALZFterry/article/details/109311390