码迷,mamicode.com
首页 > 其他好文 > 详细

Lists and strings

时间:2014-07-15 09:00:12      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   2014   io   cti   

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

标签:style   blog   http   2014   io   cti   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!