>> list(s)['x', 'x', 'x', 'x', 'x']>>> tuple(s)('x', 'x', 'x', 'x', 'x')>>> tuple(list(s))(_元组变字符串">
赞
踩
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')" >>> |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。