python - 如何从元组返回带引号的字符串?

标签 python tuples

我有一个字符串元组,我想将其内容提取为带引号的字符串,即

tup=('string1', 'string2', 'string3')

when i do this

main_str = ",".join(tup)

#i get

main_str = 'string1, string2, string3'

#I want the main_str to have something like this

main_str = '"string1", "string2", "string3"'

加思

最佳答案

", ".join('"{0}"'.format(i) for i in tup)

", ".join('"%s"' % i for i in tup)

关于python - 如何从元组返回带引号的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1439862/

相关文章:

python - 在 true_divide 中遇到无效值

python - 推荐一个 Django 项目在 Linux 上运行的地方

python - 向下滚动无法正常工作(Python)

python - 将元组列表写入 txt 文件

python - 如何从字符串元组列表中检索元组

python - 将元组的一个元素作为参数与其他参数一起传递

python - python2.5 virtualenv 中的 MySQLdb

python - Dask 中的 read_sql_table 返回 NoSuchTableError

python - 如何替换元组列表中的某些字符

python,将字典拆分为元组列表