The type constructor tuple(seq) converts any sequence (actually, any iterable) into a tuple with the same items in the same order.
For example, tuple([1, 2, 3]) yields (1, 2, 3) and tuple('abc') yields ('a', 'b', 'c'). If the argument is a tuple, it does not make a copy but returns the same object, so it is cheap to call tuple() when you aren’t sure that an object is already a tuple.
The type constructor list(seq) converts any sequence or iterable into a list with the same items in the same order. For example, list((1, 2, 3))yields [1, 2, 3] and list('abc') yields ['a', 'b', 'c']. If the argument is a list, it makes a copy just like seq[:] would.
转载:http://blog.csdn.net/sruru/article/details/7803208
python中有三个内建函数:列表,元组和字符串,他们之间的互相转换使用三个函数,str(),tuple()和list(),具体示例如下所示:
>>> s = "xxxxx" >>> list(s) ['x', 'x', 'x', 'x', 'x'] >>> tuple(s) ('x', 'x', 'x', 'x', 'x') >>> tuple(list(s)) ('x', 'x', 'x', 'x', 'x') >>> list(tuple(s)) ['x', 'x', 'x', 'x', 'x'] |
>>> "".join(tuple(s)) 'xxxxx' >>> "".join(list(s)) 'xxxxx' >>> str(tuple(s)) "('x', 'x', 'x', 'x', 'x')" >>> |