参考文章:python 怎么将列表转换成字符串
temp_list = ['h', 'e', 'l', 'l', 'o']result = ''.join(temp_list)print(result) # hello
join函数doc:
def join(self, iterable): # real signature unknown; restored from __doc__"""S.join(iterable) -> strReturn a string which is the concatenation of the strings in theiterable. The separator between elements is S.返回一个字符串,该字符串是迭代器(可迭代对象)中字符串的串联。 元素之间的分隔符是S。"""return ""
例如:
temp_list = ['h', 'e', 'l', 'l', 'o']result = '-'.join(temp_list)print(result) # h-e-l-l-o
0214
如果想实现字符串拼接,可使用:
# 用“+”连接字符串不建议使用,占用内存较大;建议使用join()方法,用''将可迭代字符串连接起来# obj_strs = obj_strs + class_num + (' {:.6f} {:.6f} {:.6f} {:.6f}\n'.format(c1, c2, d1, d2))obj_strs = ''.join([obj_strs, class_num, ' {:.6f} {:.6f} {:.6f} {:.6f}\n'.format(c1, c2, d1, d2)])print(obj_strs)