Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I would like to ask, how to use print() in python3 to print the double quote (compulsory).

The code:

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

str0 looks like a list but it is a string. Using print(), the double quotes are not shown. How to use the print(), but let the quotes shown? It should be like: "['1', 'text', 25]" ?

Thanks for the help!

like image 464
Rt Rtt Avatar asked Jan 21 '18 10:01

Rt Rtt


1 Answers

It looks like you want to print what the string would look like if you were to assign it as a literal. For that, use repr, like this:

print(repr(str0))

will print

"['1', 'text', 25]"
like image 99
cco Avatar answered Nov 02 '22 23:11

cco