将列表中的字符以逗号分割的形式提取出来

前言:

作者:神的孩子在歌唱

大家好,我叫智

可以通过join将列表中的字符提取出来以逗号分隔

a_list = ['1.1.1.2','1.1.1.3']
print(','.join(a_list))

输出如下

在这里插入图片描述

可是我想输出的是 '1.1.1.2','1.1.1.3',那么可以通过循环方式为每个值添加""

print(','.join("'{s}'".format(s=s) for s in a_list))

在这里插入图片描述

本人csdn博客:https://blog.csdn.net/weixin_46654114

转载说明:跟我说明,务必注明来源,附带本人博客连接。

猜你喜欢

转载自blog.csdn.net/weixin_46654114/article/details/125698751