在python中加入字符串列表,并将每个字符串都用引号引起来 [英] Join a list of strings in python and wrap each string in quotation marks

查看:600
本文介绍了在python中加入字符串列表,并将每个字符串都用引号引起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

words = ['hello', 'world', 'you', 'look', 'nice']

我想要拥有:

'"hello", "world", "you", "look", "nice"'

使用Python做到这一点最简单的方法是什么?

What's the easiest way to do this with Python?

推荐答案

>>> words = ['hello', 'world', 'you', 'look', 'nice']
>>> ', '.join('"{0}"'.format(w) for w in words)
'"hello", "world", "you", "look", "nice"'

这篇关于在python中加入字符串列表,并将每个字符串都用引号引起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆