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

 

shell> vi 2.py

  1. #!/usr/bin/env python
  2. str = ("i am a worker, and you are a student !")
  3. print str
  4. #split the str,if not specified the separator ,the whitespace is a separator,items is a sequence
  5. items = str.split()
  6. print items
  7. #join the str
  8. sep=":"
  9. items=sep.join(items)
  10. 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版权协议,转载请附上原文出处链接和本声明。