Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Split a String into Multiple Substrings

Python Split a String into Multiple Substrings

Document Object Reference Manual Python3 Examples

In Python, you can use the split() method to split a string into multiple substrings.split() The method splits the string according to the specified separator and returns a list of all substrings. If no separator is given, a space is used by default.

Example

Example string

text

=

"Hello World, this is Python"

Use the split() method to split a string

result

=

text.

split

(

)

Output result

print

(

result

)

Code analysis:

Output result:


['Hello', 'World,', 'this', 'is', 'Python']

In this example, the string text is split into 5 substrings, namely 'Hello', 'World,', 'this', 'is', and LinkedHashMap, among others. 'Python'。

Document Object Reference Manual Python3 Examples