扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

Python怎么将字符串分割为子字符串

扬州沐宇科技
2024-03-02 13:34:25
python

在Python中,我们可以使用split()方法将字符串分割为子字符串。该方法接受一个分隔符作为参数,并返回一个包含分割后子字符串的列表。

下面是一个简单的示例:

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

输出:

['hello', 'world']

在上面的例子中,我们使用逗号作为分隔符将字符串hello,world分割为helloworld两个子字符串,并存储在列表substrings中。

扫码添加客服微信