如何将常规字符串转换为原始字符串?

时间:2020-06-10 17:05:12

标签: python

>>> normal="The\n\t\n quick silver fox ran over lazy dog's"
>>> normal
"The\n\t\n quick silver fox ran over lazy dog's" # 1
>>> json.dumps(normal)
'"The\\n\\t\\n quick silver fox ran over lazy dog\'s"'
>>> r"The\n\t\n quick silver fox ran over lazy dog's"
"The\\n\\t\\n quick silver fox ran over lazy dog's"
>>> r"{}".format(normal)
"The\n\t\n quick silver fox ran over lazy dog's"
>>> rf"{normal}"
"The\n\t\n quick silver fox ran over lazy dog's"

如何使用String Formatting或F-stings将普通字符串(#1)转换为原始字符串(#2)

0 个答案:

没有答案
相关问题