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:!