[Python]一些代码段,Pythonic or non-pythonic

1. 将list转换成字符串;

1 >>> li = ['t', 'r', 'u', 's', 't']
2 >>> str(li)
3 "['t', 'r', 'u', 's', 't']"
4 >>> ''.join(li)
5 'trust'

str()只是单纯的将其转换成一个字符串,不会讲list的元素连接。

posted @ 2013-07-11 14:41  Tilney  阅读(139)  评论(0)    收藏  举报