![](/img/trans.png)
[英]Print empty string with double quotes instead of single quotes in Python
[英]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.