簡體   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