Python Split a String into Multiple Substrings
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
(
result
)
Code analysis:
text = "Hello World, this is Python": define a stringtext。result = text.split(): When usingsplit()The method splits the stringtextSplit into several substrings by spaces and store the result inresultlist.print(result): Print the split result.
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'。
Python3 Examples