How can strings be split into substrings in Python?

In Python, we can use the split() method to divide a string into sub-strings. This method takes a delimiter as a parameter and returns a list containing the divided sub-strings.

Here is a simple example:

s = "hello,world"
substrings = s.split(",")
print(substrings)

Output:

['hello', 'world']

In the example above, we used a comma as a delimiter to split the string “hello, world” into two substrings, “hello” and “world”, and stored them in the list “substrings”.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds