参考博文:http://blog.csdn.net/sruru/article/details/7803208
列表元素转换为字符串:
>>> a=['hello']
>>> b=''.join(a)
>>> b
'hello'
>>> a=['hello','python']
>>> b=''.join(a[1])
>>>
>>> b
'python'
>>>
列表元素转换为元组:
>>> def str2tuple(*str):
return str
>>> a
['hello', 'python']
>>> str2tuple(a[0],a[1])
('hello', 'python')
>>>
元组转换为字符串:
>>> a=('hello', 'python')
>>> a
('hello', 'python')
>>> ''.join(a[0])
'hello'
>>>
元组元素转换列表:
>>> a=('hello', 'python')
>>> a
('hello', 'python')
>>> list(a)
['hello', 'python']
>>> list(a[0])
['h', 'e', 'l', 'l', 'o']
>>>
>>> a='hello world!'
>>> a
'hello world!'
>>> tuple(a)
('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!')
>>> str2tuple('hello world!')
('hello world!',)
>>>
>>> a
'hello world!'
>>> list(a)
['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!']
>>> str2tuple(a)
('hello world!',)
>>> list(str2tuple(a))
['hello world!']
>>>