python 字符串split的用法分享
程序员文章站
2022-05-24 09:19:59
...
比如我们的存储的格式的:
格式的:
姓名,年龄|另外一个用户姓名,年龄
name:haha,age:20|name:python,age:30|name:fef,age:55
那我们可以通过字符串对象的split方法切割字符串对象为列表。
a = 'name:haha,age:20|name:python,age:30|name:fef,age:55'
print a.split('|')
返回结果:
['name:haha,age:20', 'name:python,age:30', 'name:fef,age:55']
通过上面的介绍,相信你对python string split有一个比较好的了解
格式的:
姓名,年龄|另外一个用户姓名,年龄
name:haha,age:20|name:python,age:30|name:fef,age:55
那我们可以通过字符串对象的split方法切割字符串对象为列表。
a = 'name:haha,age:20|name:python,age:30|name:fef,age:55'
print a.split('|')
返回结果:
['name:haha,age:20', 'name:python,age:30', 'name:fef,age:55']
通过上面的介绍,相信你对python string split有一个比较好的了解