在Python中,可以使用split()
函数将字符串按照换行符\n
进行分割。代码示例如下:
string = "Hello\nWorld\nPython"
# 使用split()函数按照换行符分割字符串
result = string.split("\n")
print(result)
输出结果为:
['Hello', 'World', 'Python']
这样就将字符串按照换行符分割成了一个包含多个元素的列表。
上一篇:按照条件将X的数量分组列表
下一篇:按照条件进行分组计算