首页 > 其他 > 详细

Lists and strings

时间:2014-07-15 08:59:53      阅读:358      评论:0      收藏:0      [点我收藏+]

A string is a sequence of characters and a list is a sequence of values, but a list of characters is not the same as a string. To convert from a string to a list of characters, you can use the list function:

bubuko.com,布布扣                       

list breaks a string into individual letters. If you want to break a string into words, you can use split method:

 bubuko.com,布布扣

An optional argument called a delimiter specifies which characters to use as word boundaries. The following example uses ‘, ‘ ( a comma followed by a space) as the delimiter:

 bubuko.com,布布扣

join is the inverse of split.  It takes a list of strings and concatenates the elements. join is a string method, so you have to invoke it on the delimiter and pass the list as a parameter:

 bubuko.com,布布扣

In this case, delimiter is a space character, so join puts a space between words. to concatenate strings without spaces, you can use the empty string, ‘’ as delimiter.

 

from Thinking in Python

Lists and strings,布布扣,bubuko.com

Lists and strings

原文:http://www.cnblogs.com/ryansunyu/p/3841558.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!