在Python中,我们可以使用split()方法将字符串分割为子字符串。该方法接受一个分隔符作为参数,并返回一个包含分割后子字符串的列表。
下面是一个简单的示例:
s = "hello,world"substrings = s.split(",")print(substrings)输出:
['hello', 'world']在上面的例子中,我们使用逗号作为分隔符将字符串hello,world分割为hello和world两个子字符串,并存储在列表substrings中。
在Python中,我们可以使用split()方法将字符串分割为子字符串。该方法接受一个分隔符作为参数,并返回一个包含分割后子字符串的列表。
下面是一个简单的示例:
s = "hello,world"substrings = s.split(",")print(substrings)输出:
['hello', 'world']在上面的例子中,我们使用逗号作为分隔符将字符串hello,world分割为hello和world两个子字符串,并存储在列表substrings中。