演示了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:!
#!/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:!
相关文章推荐
- Python中通过多个字符分割(split)字符串的方法
- Python中通过多个字符分割(split)字符串的方法--转载
- Python中通过多个字符分割(split)字符串的方法
- Python中split通过多个字符分割字符串
- Python_连接List与分割字符串_join&split
- 在Python中用split()方法分割字符串的使用介绍
- Python中通过多个字符分割(split)字符串的方法
- 在Python中用split()方法分割字符串的使用介绍
- python split使用多个分隔符分割字符串
- Python中通过多个字符分割(split)字符串的方法
- 黄聪:Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- JavaScript 使用split 以中英文逗号、空格(一个或多个)分割字符串
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 【Java学习笔记】使用split()方法分割字符串
- c#使用Split方法分割字符串
- C#中使用Split方法分割字符串和Replaced的使用
- MS SQL_使用for xml path 将1列多行转换为字符串连接起来
- python里使用正则表达式来分割字符串