printing double quotes around a variable

前端 未结 7 1383
闹比i
闹比i 2020-11-29 11:50

For instance, we have:

word = \'Some Random Word\'
print \'\"\' + word + \'\"\'

is there a better way to print double quotes around a varia

相关标签:
7条回答
  • 2020-11-29 12:53

    Using format method or f-string with repr(), you can write it more elegant.

    a = "foo"
    print("{!r}".format(a))
    b = "bar"
    print(f"{b!r}")
    
    0 讨论(0)
提交回复
热议问题