-1

To be clear, I do not want to print double quotes themselves, I want python to print out my strings in double quotes, instead of single quotes?

for example, if i run the following code in python-

print(["this is a string!", "this is another string!"])

the result will be

['this is a string!', 'this is another string!']

i want the output to be in double quotes aswell. How do i do this?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 3
    Does this answer your question? [Return a variable in a Python list with double quotes instead of single](https://stackoverflow.com/questions/32606599/return-a-variable-in-a-python-list-with-double-quotes-instead-of-single) – Random Davis Dec 08 '21 at 17:38
  • 1
    Why does it matter? The two representations are equivalent. – Barmar Dec 08 '21 at 17:40
  • What output type to you want ? You want the string to **contain** double quotes or just when the display way ? – azro Dec 08 '21 at 17:44

1 Answers1

0

Use json.dumps, that will make a whole string, and the inner string will be double-quoted

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!"]
azro
  • 53,056
  • 7
  • 34
  • 70
  • This is essentially the same solution that's in the [post](https://stackoverflow.com/questions/32606599/return-a-variable-in-a-python-list-with-double-quotes-instead-of-single) that this duplicates; I think rather than duplicating the solution to a duplicate question, it would be better to just mark this as a duplicate and move on. – Random Davis Dec 08 '21 at 17:41