Double Quotes in Python

PYTHON


How to add double quotes to string in python

/media/uploads/2020/09/25/image.png

>>> my_str = " ".join([a.strip() for a in b.split("\n") if a])
>>> print '"' + my_str + '"'     # Use single quotes to surround the double quotes
"a b c d e f g"
>>> print "\"" + my_str + "\""   # Escape the double quotes
"a b c d e f g"
>>> print '"%s"' % my_str        # Use old-style string formatting
"a b c d e f g"
>>> print '"{}"'.format(my_str)  # Use the newer format method
"a b c d e f g"

>>> print(f'"{my_str}"')         # Use an f-string
"a b c d e f g"  

 

 

 

            Related
Double Quotes in Python