简体   繁体   中英

How do I print a string in double quotes? (NOT PRINT DOUBLE QUOTES)

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?

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!"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM