Home  >  Article  >  Backend Development  >  python 字符串split的用法分享

python 字符串split的用法分享

WBOY
WBOYOriginal
2016-06-06 11:27:551095browse

比如我们的存储的格式的:

格式的:

姓名,年龄|另外一个用户姓名,年龄

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有一个比较好的了解

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn