您的位置:首页 > 编程语言 > Python开发

演示了Python中的字符串通过split分割后的使用和把分割后的字符串连接起来

2008-08-27 14:30 731 查看
shell> vi 2.py

#!/usr/bin/env python

str = ("i am a worker, and you are a student !")

print str

#split the str,if not specified the separator ,the whitespace is a separator,items is a sequence

items = str.split()

print items

#join the str

sep=":"

items=sep.join(items)

print items

执行这个脚本2.py,得到的结果为:
i am a worker, and you are a student !
['i', 'am', 'a', 'worker,', 'and', 'you', 'are', 'a', 'student', '!']
i:am:a:worker,:and:you:are:a:student:!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐