The results of list.split() and list.split(" ") in python are different

Problems encountered:

The results obtained by the two segmentation methods are different.

Answer:

list.split(" ") means splitting with spaces as separators,

list.split() defaults to all empty characters, including spaces, newlines (\n), tabs (\t), etc.

different ah different~


The specific syntax of the python split() method:

describe

Python split() slices the string by the specified delimiter, and if the parameter num has a specified value, separates num+1 substrings.

grammar

split() method syntax:

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

parameter

  • str -- delimiter, the default is all null characters, including spaces, newlines (\n), tabs (\t), etc.
  • num -- number of splits. Defaults to -1, which separates all.

return value

Returns a list of split strings.

Guess you like

Origin blog.csdn.net/panlan7/article/details/124000071