我正在尝试使用显式字符串和范围构建字符串元素列表(以避免键入数百个字符串)。但是,当我尝试将列表中的所有元素转换为单个字符串时,整个范围元素(范围(115,131)将转换为非常长的字符串。代码如下。
list1 = ["100","105","110",range(115,131),"135"]
print list1
[str(i) for i in list1]
最终返回:
['100','105','110','[115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130] ','135']
我希望它返回(所有项目都作为单个字符串):
['100','105','110','115','116','117','118','119','120','121','122','123 ','124','125','126','127','128','129','130','135']