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:!
版权声明:本文为lllxy原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。