如何在python中编写字符串文字而不必将其转义? [英] How to write string literals in python without having to escape them?

查看:127
本文介绍了如何在python中编写字符串文字而不必将其转义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在python中声明一个字符串变量,使其中的所有内容都被自动转义,或者具有字面值?

Is there a way to declare a string variable in python such that everything inside of it is automatically escaped, or has its literal character value?

我不是请问如何用斜杠逃避引号,这很明显。我要求的是一个通用的方式,使所有的字符串字面值,所以我不必手动通过并且逃避一切非常大的字符串。任何人知道解决方案?谢谢!

I'm not asking how to escape the quotes with slashes, that's obvious. What I'm asking for is a general purpose way for making everything in a string literal so that I don't have to manually go through and escape everything for very large strings. Anyone know of a solution? Thanks!

推荐答案

原始字符串文字:

>>> r'abc\dev\t'
'abc\\dev\\t'

这篇关于如何在python中编写字符串文字而不必将其转义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆