Home >Backend Development >Python Tutorial >What does split mean in python?

What does split mean in python?

silencement
silencementOriginal
2019-05-18 11:19:47138284browse

Split in Python is a built-in function used to split strings. The split strings are returned in list form. The syntax of this function is "str.split(str="", num=string .count(str))”.

What does split mean in python?

The English translation of split is split. split() in Python splits a string into multiple strings and returns them in the form of a list.

Syntax: str.split(str="", num=string.count(str)), parameters: str -- separator, The default is all empty characters, including spaces, newlines (\n), tabs (\t), etc.; num -- the number of divisions. The default is -1, which separates everything. In other words, split() will be split by spaces when it takes no parameters, and when it is a parameter, it will be split by this parameter.

For example:

Without parameters

What does split mean in python?

Conclusion: When there are no parameters, the default is to use spaces as parameters, no matter where the spaces are, or if there are several, all of them are removed!

With parameters

What does split mean in python?

##The result is: ['', '', 'song', '', '', 'huan', '', '', '', 'gong', '']

The above is the detailed content of What does split mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more