繁体   English   中英

如何在双引号中打印字符串? (不打印双引号)

[英]How do I print a string in double quotes? (NOT PRINT DOUBLE QUOTES)

需要明确的是,我不想自己打印双引号,我希望 python 用双引号而不是单引号打印出我的字符串?

例如,如果我在 python 中运行以下代码-

print(["this is a string!", "this is another string!"])

结果将是

['this is a string!', 'this is another string!']

我希望 output 也用双引号引起来。 我该怎么做呢?

使用json.dumps ,这将构成一个完整的字符串,内部字符串将被双引号

v = ["this is a string!", "this is another string!"]

# type is list
print(v) # ['this is a string!', 'this is another string!']

# type is string
print(json.dumps(v)) # ["this is a string!", "this is another string!"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM