python 3 : How to use print() to print a string with quote?

标签 python python-3.x

请问,如何在python3中使用print()打印双引号(必填)。

代码:

>>> List0 = ["1", "text", 25]
>>> print(List0)
['1', 'text', 25]
>>> str0 = str(List0)
>>> print(str0)
['1', 'text', 25]

str0 看起来像一个列表,但它是一个字符串。使用 print(),不会显示双引号。如何使用print(),但让引号显示出来?它应该是这样的:['1', 'text', 25]" ?

感谢您的帮助!

最佳答案

如果您将字符串分配为文字,您似乎想要打印该字符串的样子。为此,使用 repr,如下所示:

print(repr(str0))

将打印

"['1', 'text', 25]"

关于 python 3 : How to use print() to print a string with quote?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48365860/

相关文章:

Python——Python路径

python - 使用图像模块(python)将希伯来语文本绘制为图像

python - 为什么 tf.get_variable ('test' ) 返回名为 test_1 的变量?

拆分字符串并解压缩为变量的 Pythonic 方法?

python - 在 View 中找不到 Django Reverse,但 URL 有效

python psycopg2选择时区的current_timestamp问题

python - 如何使用rasterio更改光栅的crs?

python - celery - 链中的组

python - 装修契约(Contract)

c++ - 无法从C++启动可执行文件