Py&禅

博客园 首页 新随笔 联系 订阅 管理
Problem:
将若干个字符串合并到一起

Solution:
使用 ''.join()来实现对字符串列表的合并。(效率较高)
largestring = ''.join(smallpieces)
使用%格式符号
largeString = '%s%s something %s yet more' % (small1, small2, small3)
或使用 reduce()
import operator
largeString = reduce(operator.add, pieces, '')

posted on 2010-05-31 07:18  Py&禅  阅读(141)  评论(0)    收藏  举报