在Python中,可以使用split()方法来按照指定的分隔符对字符串进行分割。
下面是一个简单的例子:
string = "apple,banana,orange"# 按逗号分隔字符串result = string.split(",")print(result)输出:
['apple', 'banana', 'orange']在这个例子中,我们使用逗号作为分隔符将字符串string分割成了一个列表result。
在Python中,可以使用split()方法来按照指定的分隔符对字符串进行分割。
下面是一个简单的例子:
string = "apple,banana,orange"# 按逗号分隔字符串result = string.split(",")print(result)输出:
['apple', 'banana', 'orange']在这个例子中,我们使用逗号作为分隔符将字符串string分割成了一个列表result。